public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/66383 (aggregate NSDMI issue)
Date: Tue, 09 Jun 2015 14:12:00 -0000	[thread overview]
Message-ID: <5576F44D.6040409@redhat.com> (raw)

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

In this testcase we end up with the initializer for the A subobject 
referring to the address of the B PLACEHOLDER_EXPR, which wasn't getting 
replaced properly because when we see the A TARGET_EXPR we stopped 
looking for more PLACEHOLDER_EXPRs.  Instead, we need to keep looking, 
and learn how to handle placeholders for enclosing objects as well as 
the innermost one.

Tested x86_64-pc-linux-gnu, applying to trunk and 5.

[-- Attachment #2: 66383.patch --]
[-- Type: text/x-patch, Size: 2327 bytes --]

commit 26b958fac8f8c42ab0158583c6a362caf4a9ab73
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jun 5 17:07:23 2015 -0400

    	PR c++/66383
    	* tree.c (replace_placeholders_r): Handle placeholders for an
    	outer object.
    	* typeck2.c (store_init_value): Only replace_placeholders for
    	objects of class type.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 3c4b527..3553d7c 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2552,15 +2552,15 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
   switch (TREE_CODE (*t))
     {
     case PLACEHOLDER_EXPR:
-      gcc_assert (same_type_ignoring_top_level_qualifiers_p
-		  (TREE_TYPE (*t), TREE_TYPE (obj)));
-      *t = obj;
-      *walk_subtrees = false;
-      break;
-
-    case TARGET_EXPR:
-      /* Don't mess with placeholders in an unrelated object.  */
-      *walk_subtrees = false;
+      {
+	tree x = obj;
+	for (; !(same_type_ignoring_top_level_qualifiers_p
+		 (TREE_TYPE (*t), TREE_TYPE (x)));
+	     x = TREE_OPERAND (x, 0))
+	  gcc_assert (TREE_CODE (x) == COMPONENT_REF);
+	*t = x;
+	*walk_subtrees = false;
+      }
       break;
 
     case CONSTRUCTOR:
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index affa265..22a5580 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -836,7 +836,7 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
       TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl);
     }
 
-  if (cxx_dialect >= cxx14)
+  if (cxx_dialect >= cxx14 && CLASS_TYPE_P (strip_array_types (type)))
     /* Handle aggregate NSDMI in non-constant initializers, too.  */
     value = replace_placeholders (value, decl);
 
diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr3.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr3.C
new file mode 100644
index 0000000..185ea10
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr3.C
@@ -0,0 +1,43 @@
+// PR c++/66383
+// { dg-do compile { target c++11 } }
+
+namespace N1 {
+  struct B;
+
+  struct A
+  {
+    B* b;
+    A(B* b);
+  };
+
+  struct B
+  {
+    A a{ this };
+  };
+
+  A::A(B* b): b{ b } {}
+
+  void foo()
+  {
+    auto b = B{};
+  }
+}
+
+namespace N2 {
+  struct B;
+
+  struct A
+  {
+    B* b;
+  };
+
+  struct B
+  {
+    A a{ this };
+  };
+
+  void foo()
+  {
+    auto b = B{};
+  }
+}

                 reply	other threads:[~2015-06-09 14:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=5576F44D.6040409@redhat.com \
    --to=jason@redhat.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).