[C++] PR 53210

Message ID 5051F075.402@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Sept. 13, 2012, 2:40 p.m.

On 09/13/2012 03:38 PM, Jason Merrill wrote:
> On 09/13/2012 09:28 AM, Paolo Carlini wrote:
>> Jon noticed that for this testcase we don't warn at all even with -Wall,
>> whereas the code doesn't really make much sense. Turns out that the
>> warning is currently controlled both by warn_init_self (not part of
>> -Wall) and OPT_Wuninitialized. Thus Manuel proposes to simply remove the
>> former, because this isn't the specific case of int x = x which we want
>> to keep on "supporting" as a GNU extension. Also, as mentioned by Jon,
>> the user can always leave 'i' out the mem-initializer-list.
>> Alternately, one may want to use OPT_Winit_self, but then we still have
>> the issue that -Winit-self is not part of -Wall.
> I think my preference would be to add -Winit-self to -Wall for C++; 
> people can use -Wno-init-self if they don't want the warning.
Agreed. Then I'm finishing testing the below (already booted and tested 
C++, the other languages next). Ok?


2012-09-13  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53210
	* doc/invoke.texi ([Winit-self]): Document as enabled by -Wall in C++.

2012-09-13  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53210
	* c.opt ([Winit-self]): Enabled by -Wall in C++.

2012-09-13  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53210
	* g++.dg/warn/Wuninitialized-self.C: New.


Jason Merrill Sept. 13, 2012, 2:45 p.m. | #1



Index: testsuite/g++.dg/warn/Winit-self.C
--- testsuite/g++.dg/warn/Winit-self.C	(revision 0)
+++ testsuite/g++.dg/warn/Winit-self.C	(revision 0)
@@ -0,0 +1,8 @@ 
+// PR c++/53210
+// { dg-options "-Wall" }
+struct S
+  S(int i) : j(j) { }  // { dg-warning "is initialized with itself" }
+  int j;
Index: doc/invoke.texi
--- doc/invoke.texi	(revision 191245)
+++ doc/invoke.texi	(working copy)
@@ -3348,6 +3348,8 @@  int f()
 @end group
 @end smallexample
+This warning is enabled by @option{-Wall} in C++.
 @item -Wimplicit-int @r{(C and Objective-C only)}
 @opindex Wimplicit-int
 @opindex Wno-implicit-int
Index: c-family/c.opt
--- c-family/c.opt	(revision 191245)
+++ c-family/c.opt	(working copy)
@@ -408,7 +408,7 @@  C C++ Var(warn_ignored_qualifiers) Warning Enabled
 Warn whenever type qualifiers are ignored.
-C ObjC C++ ObjC++ Var(warn_init_self) Warning
+C ObjC C++ ObjC++ Var(warn_init_self) Warning LangEnabledBy(C++ ObjC++,Wall)
 Warn about variables which are initialized to themselves