http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46732
Summary: Valgrind emits false(?) alarms on boost::make_shared Product: gcc Version: 4.4.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: dgstef...@numerica.us Compiling the following code with 4.4.4 and running it under Valgrind produces what look like (and I hope are) false alarms. After some discussion with the Boost people, the conclusion is that it's a compiler bug. Here's the code (preprocessed code attached as well) #include <iostream> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> using std::cout; using std::endl; using boost::make_shared; namespace Numerica { class StateSpace { public: enum SpaceType { Unknown = 0, ECI, ECEF, Topo }; StateSpace(SpaceType spaceType) { if (spaceType == Topo) cout << "origin required for topocentric system" << endl; } }; class State { public: State() : m_rep(make_shared<StateRep>(StateSpace::Unknown) ) {} protected: struct StateRep { StateRep(StateSpace theStateSpace) : stateSpace(theStateSpace) { } StateSpace stateSpace; }; typedef boost::shared_ptr<StateRep> StateRepPtr; StateRepPtr m_rep; }; } // end of namespace Numerica using namespace Numerica; using namespace std; int main() { State state; } Here is the Valgrind output: ==478== Memcheck, a memory error detector ==478== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==478== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==478== Command: testStateSpace ==478== ==478== Conditional jump or move depends on uninitialised value(s) ==478== at 0x401749: Numerica::StateSpace::StateSpace(Numerica::StateSpace::SpaceType) (testDaveCase.cpp:26) ==478== by 0x40186F: boost::shared_ptr<Numerica::State::StateRep> boost::make_shared<Numerica::State::StateRep, Numerica::StateSpace::SpaceType, >(Numerica::StateSpace::SpaceType&&, ) (make_shared.hpp:150) ==478== by 0x4017AD: Numerica::State::State() (testDaveCase.cpp:39) ==478== by 0x401407: main (testDaveCase.cpp:78) ==478== ==478== ==478== HEAP SUMMARY: ==478== in use at exit: 464 bytes in 5 blocks ==478== total heap usage: 1,080 allocs, 1,076 frees, 85,240 bytes allocated ==478== ==478== LEAK SUMMARY: ==478== definitely lost: 0 bytes in 0 blocks ==478== indirectly lost: 0 bytes in 0 blocks ==478== possibly lost: 0 bytes in 0 blocks ==478== still reachable: 464 bytes in 5 blocks ==478== suppressed: 0 bytes in 0 blocks ==478== Reachable blocks (those to which a pointer was found) are not shown. ==478== To see them, rerun with: --leak-check=full --show-reachable=yes ==478== ==478== For counts of detected and suppressed errors, rerun with: -v ==478== Use --track-origins=yes to see where uninitialised values come from ==478== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 5 from 5) Here's the compile command /usr/local/compilers/4.4.4/bin/c++ -o dynamics/state/Test/testStateSpace.o -c -isystem/usr/local/Boost/1.44 -isystem/usr/include/python2.6 -isystem/home/dgsteffen/local/kml/include -ansi -Wall -Wextra -pedantic -Wno-long-long -Wmissing-include-dirs -fshow-column -pthread -g -fdiagnostics-show-option -std=c++0x -Woverloaded-virtual -Wno-write-strings -DBOOST_TEST_DYN_LINK -I. dynamics/state/Test/testStateSpace.cpp /usr/local/compilers/4.4.4/bin/c++ -o dynamics/state/Test/testStateSpace -Wl,-rpath=/home/dgsteffen/Local/MFATS/testcase/lib -Wl,-rpath=/usr/local/Boost/1.44/lib/4.4 -Wl,-rpath=/home/dgsteffen/local/kml/lib -Wl,-rpath=/usr/local/compilers/4.4.4/lib64 -pthread dynamics/state/Test/testStateSpace.o -Llib -L/usr/local/Boost/1.44/lib/4.4 -L/usr/lib64/python2.6/config -L/home/dgsteffen/local/kml/lib -lboost_unit_test_framework -lnumerica_dynamics -lnumerica_math -llapack -lblas -lnumerica_util -lboost_signals -lboost_filesystem -lboost_iostreams -lboost_thread -lboost_system scons: done building targets. Compiler info: /usr/local/compilers/4.4.4/bin/c++ -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: /home/seroberts/gcc-4.4.4/configure --prefix=/usr/local/compilers/.gcc-4.4.4 --enable-languages=c,c++ --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --enable-shared --enable-checking=release --disable-multilib --enable-clocale=gnu --with-mpfr=/usr/local/compilers/mpfr/3.0.0 --with-gmp=/usr/local/compilers/gmp/4.3.2 Thread model: posix gcc version 4.4.4 (GCC)