re PR c++/64667 (-Winit-self ignored for reference fields)
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 29 Apr 2015 14:06:27 +0000 (14:06 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 29 Apr 2015 14:06:27 +0000 (14:06 +0000)
/cp
2015-04-29  Paolo Carlini  <paolo.carlini@oracle.com>

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

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

PR c++/64667
* g++.dg/warn/Winit-self-3.C: New.

From-SVN: r222577

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Winit-self-3.C [new file with mode: 0644]

index cc716b86160c5b64d0fb7c184bbd99037943b5d0..3ee050ce7536bb80922088e72bf44a373de1c786 100644 (file)
@@ -1,3 +1,8 @@
+2015-04-29  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/64667
+       * init.c (perform_member_init): Handle references for -Winit-self.
+
 2015-04-29  Thomas Schwinge  <thomas@codesourcery.com>
 
        * pt.c (tsubst_expr) <OMP_TARGET_UPDATE>: Use
index 957a7a4e6e8823096536bb974e95c2208b971a6f..a4fc9ff33cdd7d09f4258e14eb5312e2f04fda34 100644 (file)
@@ -625,6 +625,9 @@ perform_member_init (tree member, tree init)
       && TREE_CHAIN (init) == NULL_TREE)
     {
       tree val = TREE_VALUE (init);
+      /* Handle references.  */
+      if (REFERENCE_REF_P (val))
+       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 3ec7673054849b9c37df40089530e454ac852ac9..df61b1c15b96de04cddf6b04c3790eae79c4c6b6 100644 (file)
@@ -1,3 +1,8 @@
+2015-04-29  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/64667
+       * g++.dg/warn/Winit-self-3.C: New.
+
 2015-04-29  Uros Bizjak  <ubizjak@gmail.com>
 
        * gfortran.dg/namelist_87.f90: Use dg-add-options ieee.
diff --git a/gcc/testsuite/g++.dg/warn/Winit-self-3.C b/gcc/testsuite/g++.dg/warn/Winit-self-3.C
new file mode 100644 (file)
index 0000000..dd06ad0
--- /dev/null
@@ -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;
+};