diff mbox

[C++] PR 64667

Message ID 5540D40F.9090103@oracle.com
State New
Headers show

Commit Message

Paolo Carlini April 29, 2015, 12:52 p.m. UTC
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.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.

Comments

Jason Merrill April 29, 2015, 1:28 p.m. UTC | #1
On 04/29/2015 08:52 AM, Paolo Carlini wrote:
> +      /* Handle references.  */
> +      if (TREE_CODE (val) == INDIRECT_REF)

Let's use REFERENCE_REF_P here.  OK with that change.

Jason
diff mbox

Patch

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;
+};