/* Spurious "might be used uninitialized" warning in STL use. The following short program produces a spurious warning. The quoted function in stl_uninitialized.h is template<typename _InputIterator, typename _ForwardIterator> inline _ForwardIterator __uninitialized_copy_aux(_InputIterator __first, _InputIterator __last, _ForwardIterator __result, __false_type) { _ForwardIterator __cur = __result; // this is line 82 try { for ( ; __first != __last; ++__first, ++__cur) std::_Construct(&*__cur, *__first); return __cur; } catch(...) { std::_Destroy(__result, __cur); __throw_exception_again; } }
We see this warning in other circumstances on several gcc versions, always in STL headers and usually in very simple statements of the form "sometype a = b;" where 'a' is reported a uninitialized (sic!). The sample given here compiles without warnings with -O1, but this is not generally the case. Any solutions or work-arounds? */ #include <iostream> #include <ostream> #include "boost/format.hpp" int main() { std::cout << boost::format("0x%04x ") % 42 << std::endl; } /* $ uname -a CYGWIN_NT-5.1 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin $ gcc --version gcc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) $ g++ -ansi -Wall -O2 -I/cygdrive/d/Info/boost_1_32_0/ simpleformat.cpp /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_uninitialized.h: In member function `void std::vector<_Tp, _Alloc>::_M_fill_insert( __gnu_cxx::__normal_iterator<typename _Alloc::pointer, std::vector<_Tp, _Alloc> >, size_t, const _Tp&) [with _Tp = boost::io::detail::format_item<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<boost::io::detail::format_item<char, std::char_traits<char>, std::allocator<char> > >]': /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 */ -- Summary: Spurious "might be used uninitialized" warning in STL use. Product: gcc Version: 3.4.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hartog at best dot ms dot philips dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30680