* [C++ Patch] PR 64667
@ 2015-04-29 13:21 Paolo Carlini
2015-04-29 13:39 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2015-04-29 13:21 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 247 bytes --]
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.
////////////////////
[-- Attachment #2: CL_64667 --]
[-- Type: text/plain, Size: 258 bytes --]
/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.
[-- Attachment #3: patch_64667 --]
[-- Type: text/plain, Size: 1237 bytes --]
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;
+};
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ Patch] PR 64667
2015-04-29 13:21 [C++ Patch] PR 64667 Paolo Carlini
@ 2015-04-29 13:39 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2015-04-29 13:39 UTC (permalink / raw)
To: Paolo Carlini, gcc-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-04-29 13:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-29 13:21 [C++ Patch] PR 64667 Paolo Carlini
2015-04-29 13:39 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).