===================================================================
@@ -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),
===================================================================
@@ -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;
+};