This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34772] New: -Winit-self ignored when compiling C++ (and ObjC++)
- From: "olly at survex dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Jan 2008 18:01:41 -0000
- Subject: [Bug c++/34772] New: -Winit-self ignored when compiling C++ (and ObjC++)
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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