Here, when we're trying to find the matching object for a
PLACEHOLDER_EXPR, we need to look through ARRAY_REF.  Fixed by using
handled_component_p in the assert.

Tested x86_64-pc-linux-gnu, applying to trunk and 7.
commit 012c92312a0713370b54acaf3c9c7df3a03cae31
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Apr 3 15:21:30 2018 -0400

            PR c++/85148 - ICE with 'this' in array NSDMI.
    
            * tree.c (replace_placeholders_r): Use handled_component_p.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index e75c88d6e8f..7ddc2cb5e2d 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -3145,7 +3145,7 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
 	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);
+	  gcc_assert (handled_component_p (x));
 	*t = unshare_expr (x);
 	*walk_subtrees = false;
 	d->seen = true;
diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr11.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr11.C
new file mode 100644
index 00000000000..09591df3807
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr11.C
@@ -0,0 +1,12 @@
+// PR c++/85148
+// { dg-do compile { target c++14 } }
+
+template<typename T> struct A
+{
+  T x[1]{(__PTRDIFF_TYPE__)this};
+};
+
+void foo()
+{
+  A<A<__PTRDIFF_TYPE__>> a{};
+}

Reply via email to