Hi,

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.

Anyway, I booted and tested the patchlet preferred by Manuel as-is.

Thanks,
Paolo.

///////////////////////////
/cp
2012-09-13  Manuel López-Ibáñez  <m...@gcc.gnu.org>

        PR c++/53210
        * init.c (perform_member_init): Remove warn_init_self check from
        "initialized with itself" warning.

/testsuite
2012-09-13  Manuel López-Ibáñez  <m...@gcc.gnu.org>

        PR c++/53210
        * g++.dg/warn/Wuninitialized-self.C: New.
Index: testsuite/g++.dg/warn/Wuninitialized-self.C
===================================================================
--- testsuite/g++.dg/warn/Wuninitialized-self.C (revision 0)
+++ testsuite/g++.dg/warn/Wuninitialized-self.C (revision 0)
@@ -0,0 +1,8 @@
+// PR c++/53210
+// { dg-options "-Wuninitialized" }
+
+struct S
+{
+  S(int i) : j(j) { }  // { dg-warning "is initialized with itself" }
+  int j;
+};
Index: cp/init.c
===================================================================
--- cp/init.c   (revision 191245)
+++ cp/init.c   (working copy)
@@ -571,7 +571,7 @@ perform_member_init (tree member, tree init)
   if (decl == error_mark_node)
     return;
 
-  if (warn_init_self && init && TREE_CODE (init) == TREE_LIST
+  if (init && TREE_CODE (init) == TREE_LIST
       && TREE_CHAIN (init) == NULL_TREE)
     {
       tree val = TREE_VALUE (init);

Reply via email to