public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "brian at dessent dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/22207] New: Spurious 'might be used uninitialized' warnings in STL headers with -O2
Date: Mon, 27 Jun 2005 23:08:00 -0000	[thread overview]
Message-ID: <20050627230816.22207.brian@dessent.net> (raw)

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


             reply	other threads:[~2005-06-27 23:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-27 23:08 brian at dessent dot net [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050627230816.22207.brian@dessent.net \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).