re PR c++/66383 (ICE in gimplify_expr on this passed in inline initialization)
authorJason Merrill <jason@redhat.com>
Tue, 9 Jun 2015 14:13:22 +0000 (10:13 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 9 Jun 2015 14:13:22 +0000 (10:13 -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.

From-SVN: r224282

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr3.C [new file with mode: 0644]

index 5160324db43eb47f971128a9adbe5fd50c1ca6fd..b71893c2fc6d3d00cc5813e9ad69e958f42c57b8 100644 (file)
@@ -1,3 +1,11 @@
+2015-06-09  Jason Merrill  <jason@redhat.com>
+
+       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.
+
 2015-06-08  Andrew MacLeod  <amacleod@redhat.com>
 
        * call.c : Adjust include files.
index 3c4b5276eb3098e8a1e61a8e1d2e5613c4b29a99..3553d7c2c9d73690e40107de9cf84c05521b6f32 100644 (file)
@@ -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:
index affa2657f453aac199cef485ef798247c0a444e0..22a55801601c5dd6334b751b5bf485b4bc8c160a 100644 (file)
@@ -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 (file)
index 0000000..185ea10
--- /dev/null
@@ -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{};
+  }
+}