Boost logo

Boost Users :

Subject: [Boost-users] [ptr_map] Warning about returning address of local variable
From: Bill Buklis (boostusr_at_[hidden])
Date: 2018-03-02 22:09:15


I'm not sure if this a potential bug/problem or just a benign warning,
but when using the map_values range adaptor with a ptr_map container I
get a warning about returning an address of a local variable. It seems
benign as the expected processing happens, but this type of warning
generally doesn't sound like a good thing.

The following useless code will trigger it.

#include <boost/ptr_container/ptr_map.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>

struct sample
{
 Â Â Â  int        value;
};

typedef boost::ptr_map<int, sample> themap;

int main()
{
 Â Â Â  themap        data;
 Â Â Â  int            key = 5;

 Â Â Â  data.insert(key, new sample);
 Â Â Â  boost::for_each(data | boost::adaptors::map_values, [](sample* s)
 Â Â Â  {
 Â Â Â      s->value = 10;
 Â Â Â  });

 Â Â Â  return 0;
}

I'm using Visual Studio 2017. I also have conformance mode
(/permissive-) turned on for stricter language compliance in case it
makes a difference.

As an aside, I was a little surprised when trying out this little sample
that the inclusion of the above headers is enough to require linking
with the boost regex library. I figure it's probably a reference in the
adaptors somewhere. It's not a big deal. These lib files are normally
available anyway.

-- 
Bill

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net