Here r16-3466 moved the canonicalization step that transforms
idx[array] to array[idx] to the beginning of cp_build_array_ref.
When we have array[array], we'll be swapping till we blow the stack.
Previously, we'd give the !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
error so there was no problem.
PR c++/125454
gcc/cp/ChangeLog:
* typeck.cc (cp_build_array_ref): Don't recurse for array[array].
gcc/testsuite/ChangeLog:
* g++.dg/other/array8.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
return error_mark_node;
/* 0[array] */
- if (TREE_CODE (TREE_TYPE (idx)) == ARRAY_TYPE)
+ if (TREE_CODE (TREE_TYPE (idx)) == ARRAY_TYPE
+ && TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE)
{
std::swap (array, idx);
--- /dev/null
+// PR c++/125454
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+void
+foo()
+{
+ T a = a[a]; // { dg-error "array subscript is not an integer" }
+}
+
+void
+bar ()
+{
+ foo<int[]>;
+}