diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 290e73bad83..7dcb453ba6a 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1340,10 +1340,12 @@ cp_build_qualified_type_real (tree type, if (!t) { - gcc_checking_assert (TYPE_DEPENDENT_P_VALID (type) - || !dependent_type_p (type)); + /* If we already know the dependentness, tell the array type + constructor. This is important for module streaming, as we cannot + dynamically determine that on read in. */ t = build_cplus_array_type (element_type, TYPE_DOMAIN (type), - TYPE_DEPENDENT_P (type)); + TYPE_DEPENDENT_P_VALID (type) + ? int (TYPE_DEPENDENT_P (type)) : -1); /* Keep the typedef name. */ if (TYPE_NAME (t) != TYPE_NAME (type)) diff --git a/gcc/testsuite/g++.dg/template/pr98538.C b/gcc/testsuite/g++.dg/template/pr98538.C new file mode 100644 index 00000000000..b62e8a96af8 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr98538.C @@ -0,0 +1,18 @@ +// PR c++/98538 +// { dg-do compile { target c++11 } } +// ICE bulding a dependent array type variant + +template using A = int[1]; +template> struct X { }; + +template +void +f (const A) +{ + const A a; +} + +template +struct Y { + const A a; +};