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
  2008-01-13 18:50 ` [Bug c++/34772] " olly at survex dot com
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ 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] 16+ messages in thread

end of thread, other threads:[~2010-05-22 18:21 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-13 18:24 [Bug c++/34772] New: -Winit-self ignored when compiling C++ (and ObjC++) olly at survex dot com
2008-01-13 18:50 ` [Bug c++/34772] " olly at survex dot com
2008-01-14  1:12 ` manu at gcc dot gnu dot org
2008-01-14  1:36 ` olly at survex dot com
2008-01-14  7:43 ` [Bug c++/34772] self-initialisation does not silence uninitialised warnings (-Winit-self ignored) manu at gcc dot gnu dot org
2008-01-14  8:32 ` manu at gcc dot gnu dot org
2008-01-14  8:59 ` pinskia at gcc dot gnu dot org
2008-01-14  9:29 ` [Bug c++/34772] [3.4/4.0/4.1/4.2/4.3 Regression] " manu at gcc dot gnu dot org
2008-01-14 10:59 ` [Bug c++/34772] [4.1/4.2/4.3 " rguenth at gcc dot gnu dot org
2008-01-20  7:02 ` pinskia at gcc dot gnu dot org
2008-07-04 22:28 ` [Bug c++/34772] [4.2/4.3/4.4 " jsm28 at gcc dot gnu dot org
2008-10-16 16:18 ` paolo dot carlini at oracle dot com
2009-03-31 20:17 ` [Bug c++/34772] [4.3/4.4/4.5 " jsm28 at gcc dot gnu dot org
2009-08-04 12:48 ` rguenth at gcc dot gnu dot org
2009-12-30 11:29 ` manu at gcc dot gnu dot org
2010-05-22 18:21 ` [Bug c++/34772] [4.3/4.4/4.5/4.6 " 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).