Hi,

Jonathan noticed in the audit trail the probably his work for c++/18016 could be easily extended to handle references: simply looking through INDIRECT_REFs appears to do the trick. Tested x86_64-linux.

Thanks,
Paolo.

////////////////////
/cp
2015-04-29  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/64667
        * init.c (perform_member_init): Handle references for -Winit-self.

/testsuite
2015-04-29  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/64667
        * g++.dg/warn/Winit-self-3.C: New.
Index: cp/init.c
===================================================================
--- cp/init.c   (revision 222561)
+++ cp/init.c   (working copy)
@@ -625,6 +625,9 @@ perform_member_init (tree member, tree init)
       && TREE_CHAIN (init) == NULL_TREE)
     {
       tree val = TREE_VALUE (init);
+      /* Handle references.  */
+      if (TREE_CODE (val) == INDIRECT_REF)
+       val = TREE_OPERAND (val, 0);
       if (TREE_CODE (val) == COMPONENT_REF && TREE_OPERAND (val, 1) == member
          && TREE_OPERAND (val, 0) == current_class_ref)
        warning_at (DECL_SOURCE_LOCATION (current_function_decl),
Index: testsuite/g++.dg/warn/Winit-self-3.C
===================================================================
--- testsuite/g++.dg/warn/Winit-self-3.C        (revision 0)
+++ testsuite/g++.dg/warn/Winit-self-3.C        (working copy)
@@ -0,0 +1,26 @@
+// PR c++/64667
+// { dg-options "-Winit-self" }
+
+class A
+{
+public:
+  A(const A&) : a(a) {}  // { dg-warning "initialized with itself" }
+private:
+  int a;
+};
+
+class B
+{
+public:
+  B(const B&) : b(b) {}  // { dg-warning "initialized with itself" }
+private:
+  int* b;
+};
+
+class C
+{
+public:
+  C(const C&) : c(c) {}  // { dg-warning "initialized with itself" }
+private:
+  int& c;
+};

Reply via email to