public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/34772]  New: -Winit-self ignored when compiling C++ (and ObjC++)
@ 2008-01-13 18:24 olly at survex dot com
  2010-05-22 18:21 ` [Bug c++/34772] [4.3/4.4/4.5/4.6 Regression] self-initialisation does not silence uninitialised warnings (-Winit-self ignored) rguenth at gcc dot gnu dot org
  0 siblings, 1 reply; 8+ messages in thread
From: olly at survex dot com @ 2008-01-13 18:24 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2082 bytes --]

The info manual says:

`-Winit-self (C, C++, Objective-C and Objective-C++ only)'
     Warn about uninitialized variables which are initialized with
     themselves.  Note this option can only be used with the
     `-Wuninitialized' option, which in turn only works with `-O1' and
     above.

     For example, GCC will warn about `i' being uninitialized in the
     following snippet only when `-Winit-self' has been specified:
          int f()
          {
            int i = i;
            return i;
          }

However, trying that exact example, I get:

$ g++-4.2 -O -Wuninitialized -c warnings.cc 
warnings.cc: In function ‘int f()’:
warnings.cc:3: warning: ‘i’ is used uninitialised in this function
$ g++-4.2 -O -Wuninitialized -Wno-init-self -c warnings.cc 
warnings.cc: In function ‘int f()’:
warnings.cc:3: warning: ‘i’ is used uninitialised in this function

Compiling the same code as C:

$ gcc-4.2 -x c -O -Wuninitialized -c warnings.cc 
$ gcc-4.2 -x c -O -Wuninitialized -Winit-self -c warnings.cc
warnings.cc: In function ‘f’:
warnings.cc:3: warning: ‘i’ is used uninitialised in this function
$

So it appears that g++ simply ignores the -Winit-self setting and always warns
about such code, contrary to what the documentation states (and gcc works as
documented).  ObjC seems to handle this as C does (as documented).  ObjC++
seems to handle it as C++ does (contrary to documentation).

This could be viewed as a documentation bug, though it seems more useful for
this to work for C++ (and ObjC++) as is currently documented.

It looks like -Winit-self was new in GCC 3.4, and I can the same behaviour for
C++ with g++ 3.4.4, so I don't think this is a regression.


-- 
           Summary: -Winit-self ignored when compiling C++ (and ObjC++)
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: olly at survex dot com


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


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

end of thread, other threads:[~2011-06-27 19:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-34772-4@http.gcc.gnu.org/bugzilla/>
2011-05-09 17:49 ` [Bug c++/34772] [4.3/4.4/4.5/4.6/4.7 Regression] self-initialisation does not silence uninitialised warnings (-Winit-self ignored) jason at gcc dot gnu.org
2011-05-09 21:04 ` [Bug c++/34772] [4.3/4.4/4.5/4.6 " jason at gcc dot gnu.org
2011-06-27 13:07 ` rguenth at gcc dot gnu.org
2011-06-27 16:43 ` [Bug c++/34772] [4.4/4.5/4.6 " manu at gcc dot gnu.org
2011-06-27 16:58 ` davi.arnaut at oracle dot com
2011-06-27 18:02 ` manu at gcc dot gnu.org
2011-06-27 19:17 ` davi.arnaut at oracle dot com
2008-01-13 18:24 [Bug c++/34772] New: -Winit-self ignored when compiling C++ (and ObjC++) olly at survex dot com
2010-05-22 18:21 ` [Bug c++/34772] [4.3/4.4/4.5/4.6 Regression] self-initialisation does not silence uninitialised warnings (-Winit-self ignored) rguenth at gcc dot gnu dot org

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).