-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 16 November 2010, Dave Steffen wrote:
==8198== Conditional jump or move depends on uninitialised value(s) ==8198== at 0x401659: StateSpace::StateSpace(int) (testState.cpp:14) ==8198== by 0x401796: boost::shared_ptr<StateSpace> boost::make_shared
(int&&, ) (make_shared.hpp:150) ==8198== by 0x4016BD: State::State() (testState.cpp:22) ==8198== by 0x401317: main (testState.cpp:29)
Any ideas about why Valgrind doesn't like the call to make_shared?
It looks like it might be a bug in make_shared's perfect forwarding when compiling in c++0x mode. When I compile your example I get a warning: $ g++ -Wall -g -std=c++0x -I ~/svn/boost_trunk/ make_shared_valgrind.cpp /svn/boost_trunk/boost/smart_ptr/make_shared.hpp: In function ‘T&& boost::detail::sp_forward(T&) [with T = int]’: /svn/boost_trunk/boost/smart_ptr/make_shared.hpp:150: instantiated from ‘boost::shared_ptr<X> boost::make_shared(Arg1&&, Args&& ...) [with T = StateSpace, Arg1 = int, Args = ]’ make_shared_valgrind.cpp:21: instantiated from here /svn/boost_trunk/boost/smart_ptr/make_shared.hpp:93: warning: returning reference to temporary
Any ideas about how to silence this warning (other than adding it to Valgrind's suppressions file)?
Not forwarding a literal constant works: class State { public: State() : m_rep(make_shared<StateSpace>(spaceType) ) {} static const int spaceType; boost::shared_ptr<StateSpace> m_rep; }; const int State::spaceType = 0; -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkzi1boACgkQ5vihyNWuA4Xq9ACggT4DQr/HzkdDTFt0na0yGLqW TLEAoKtyB8VZy61d2Ug0X8eatHjoFDsu =JMjU -----END PGP SIGNATURE-----