GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

c++: Fix infinite looping with arr[arr] [PR125454]

Fixes an infinite recursion in C++ code when an array is indexed by itself, like arr[arr].

A recent change in GCC’s C++ front-end caused an infinite recursion when handling array indexing expressions of the form array[array]. The compiler would repeatedly swap the array and index, leading to a stack overflow. This commit prevents the canonicalization step from recursing when the array is indexed by itself.

In Details

In cp_build_array_ref within typeck.cc, the canonicalization step (introduced by r16-3466) transforms idx[array] to array[idx]. When processing array[array], this swapping recurses indefinitely. Previously, the !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P error prevented this. The fix avoids the recursion.

For Context

When compiling C++ code, the compiler transforms source code into an executable form. Array indexing involves accessing elements within an array using an index. The compiler must ensure that the index is valid and of the correct type. This commit fixes a bug where the compiler would enter an infinite loop when an array was indexed by itself, which could lead to a crash.

Filed Under: c++bugfixcompiler