On 5/28/26 1:54 PM, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/16?
OK.
-- >8 -- 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. --- gcc/cp/typeck.cc | 3 ++- gcc/testsuite/g++.dg/other/array8.C | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/other/array8.C diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 483e664397b..37a0c3cfb7a 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -4162,7 +4162,8 @@ cp_build_array_ref (location_t loc, tree array, tree idx, 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);diff --git a/gcc/testsuite/g++.dg/other/array8.C b/gcc/testsuite/g++.dg/other/array8.Cnew file mode 100644 index 00000000000..d238e3ba589 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/array8.C @@ -0,0 +1,15 @@ +// 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[]>; +} base-commit: 51a122bf9bf8f01ddfd53fe9e527e93b2ef99ffb
