public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/22207] New: Spurious 'might be used uninitialized' warnings in STL headers with -O2
@ 2005-06-27 23:08 brian at dessent dot net
  2005-06-27 23:10 ` [Bug libstdc++/22207] " brian at dessent dot net
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: brian at dessent dot net @ 2005-06-27 23:08 UTC (permalink / raw)
  To: gcc-bugs

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.

-- 
           Summary: Spurious 'might be used uninitialized' warnings in STL
                    headers with -O2
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: brian at dessent dot net
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-cygwin


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22207


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-09-06 18:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-27 23:08 [Bug libstdc++/22207] New: Spurious 'might be used uninitialized' warnings in STL headers with -O2 brian at dessent dot net
2005-06-27 23:10 ` [Bug libstdc++/22207] " brian at dessent dot net
2005-06-27 23:15 ` [Bug middle-end/22207] " pinskia at gcc dot gnu dot org
2005-09-06 11:07 ` dave dot korn at artimi dot com
2005-09-06 11:28 ` james at juranfamily dot org
2005-09-06 18:59 ` ian at airs dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).