+++ This bug was initially created as a clone of Bug #22207 +++ The following reduced test case causes spurious -Wuninitialized warnings, but only with -O2:
----- #include <vector> #include <string> class OptionSet { public: OptionSet (); std::vector<std::string> const &nonOptions() const; private: std::vector<std::string> nonoptions; }; OptionSet::OptionSet() { nonoptions = std::vector<std::string> (); } std::vector<std::string> const & OptionSet::nonOptions() const { return nonoptions; } ----- $ g++ -Wuninitialized -O2 -c spurious_uninitialized_testcase.cc /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_vector.h: In member function `std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::string, _Alloc = std::allocator<std::string>]': /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_vector.h:715: warning: '__result' might be used uninitialized in this function /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_uninitialized.h:82: warning: '__cur' might be used uninitialized in this function /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_uninitialized.h:82: warning: '__cur' might be used uninitialized in this function $ g++ -v Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug : (reconfigured) Thread model: posix gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125) ----- The warnings only occur at -O2 and seem to have something to do with inlining. This causes our build that uses "-Wall -Werror" to die whereas it had no problem with this warning in gcc-3.3. I'm sensitive to the fact that it's impossible for the compiler to get this warning correct every time, and the reason for the use of "might be" in the warning text. It's acceptible to emit warnings about things that may not actually be the case, and normally I would just modify the build environment to disable that warning or lose -Werror. But in this case, the code in question is in the STL and is completely out of the hands of the user, and I don't think it's unreasonable to expect to be able to compile STL-based code with -Werror -Wall. This warnings also occur on HP/UX. gcc -v Reading specs from /opt/hp-gcc/3.4.4/ilp32/lib/gcc/hppa1.1-hp-hpux11.11/3.4.4/specs Configured with: /proj/oscp/nightly/gcc/gcc_3_4_4_release/gcc/configure --enable-languages=c,c++ --enable-threads=posix --with-ld=/usr/ccs/bin/ld --without-gnu-ld --build=hppa1.1-hp-hpux11.11 --host=hppa1.1-hp-hpux11.11 --target=hppa1.1-hp-hpux11.11 --prefix=/opt/hp-gcc/3.4.4/ilp32 --with-as=/proj/oscp/nightly/gcc/gcc_3_4_4_release/HP-UX/hppa//opt/hp-gcc/3.4.4/ilp32/bin/as Thread model: posix gcc version 3.4.4 Oliver -- Summary: Spurious 'might be used uninitialized' warnings in STL headers with -O2 Product: gcc Version: 3.4.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: oliver dot kowalke at gmx dot de GCC target triplet: hppa* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25648