public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [patch] fix c++/18016 - warn about self-initialization in constructor init-list
Date: Wed, 22 Dec 2010 00:06:00 -0000	[thread overview]
Message-ID: <AANLkTik+GX_H58khGQysNv67awsjFyj6+JKuxfb03B-Z@mail.gmail.com> (raw)
In-Reply-To: <AANLkTi=XxKA5CewBxukivwXxVsXov-MTLWTNYFSU9cGd@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 417 bytes --]

On 21 December 2010 17:11, Jonathan Wakely wrote:
> On 21 December 2010 17:04, Paolo Carlini wrote:
>> Hi,
>>
>> +  if (warn_uninitialized && init && init != NULL_TREE
>>
>> I think the last check in this line is redundant.
>
> Thanks, Paolo. I should have checked the definition of NULL_TREE.
>
> I'm re-testing with that change, but it shouldn't affect the results.

Updated patch, tested x86_64-linux

[-- Attachment #2: 18016-2.txt --]
[-- Type: text/plain, Size: 1251 bytes --]

Index: cp/init.c
===================================================================
--- cp/init.c	(revision 168023)
+++ cp/init.c	(working copy)
@@ -449,6 +449,17 @@ perform_member_init (tree member, tree i
   if (decl == error_mark_node)
     return;
 
+  if (warn_uninitialized && init && TREE_CODE (init) == TREE_LIST
+      && TREE_CHAIN (init) == NULL_TREE)
+    {
+      tree val = TREE_VALUE (init);
+      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),
+	            OPT_Wuninitialized, "%qD is initialized with itself",
+		    member);
+    }
+
   if (init == void_type_node)
     {
       /* mem() means value-initialization.  */
Index: testsuite/g++.dg/warn/pr18016.C
===================================================================
--- testsuite/g++.dg/warn/pr18016.C	(revision 0)
+++ testsuite/g++.dg/warn/pr18016.C	(revision 0)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-Wuninitialized" } */
+
+class X {
+  int i;
+  X() : i(i) { }   // { dg-warning "initialized with itself" }
+  X(int i) : i(i) { }
+  X(const X& x) : i(x.i) { }
+};
+
+// { dg-prune-output "In constructor" }

  reply	other threads:[~2010-12-21 23:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-21 16:06 Jonathan Wakely
2010-12-21 18:21 ` Paolo Carlini
2010-12-21 18:35   ` Jonathan Wakely
2010-12-22  0:06     ` Jonathan Wakely [this message]
2011-05-23  0:14 ` Jonathan Wakely
2011-05-23  9:26   ` Jason Merrill
2011-05-23  9:47     ` Jonathan Wakely
2011-05-23 14:59       ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTik+GX_H58khGQysNv67awsjFyj6+JKuxfb03B-Z@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).