On Tue, Feb 15, 2005 at 10:58:13AM +0000, Angus Leeming wrote: > class Mover {...}; > class SpecialisedMover : public Mover {...}; > > class Movers { > public: > /// @c returns the Mover registered for format @c fmt. > Mover const & operator()(std::string const & fmt) const > { > SpecialsMap::const_iterator const it = specials_.find(fmt); > return (it == specials_.end()) ? default_ : it->second; > } > > private: > typedef std::map<std::string, SpecialisedMover> SpecialsMap; > SpecialsMap specials_; > Mover default_; > }; > > MSVC warns that Movers::operator() is "returning address of local variable > or temporary". I guess that the code is indeed unsafe if it->second is a > copy of the data in the store. > > Should I change the function signature?
I am not sure the message is valid. Sure, the compiler sees a tmporary and returning a reference to a part of something refered to by the temporary. However, that thing is not a temporary but lives in a structure outside. The compiler does not know, but we do. So my guess is the code is safe and the warning is bogus. Andre'