GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/cp

C++/reflection: Fix ICE with reflection and sb packs

C++ reflection with `std::array` and `constexpr` no longer causes an internal compiler error.

This commit resolves an internal compiler error (ICE) that occurred when using C++ reflection with std::array and constexpr variables. The issue stemmed from how consteval-only variables were marked, leading to incorrect context checks. By using DECL_THIS_EXTERN instead of DECL_EXTERNAL for these variables, the compiler now correctly identifies their context, preventing the ICE and ensuring proper handling of reflection features.

In Details

The change in gcc/cp/name-lookup.cc addresses an ICE in set_decl_context_in_fn. Previously, consteval-only variables were marked DECL_EXTERNAL, which incorrectly triggered an assertion in set_decl_context_in_fn when processing static constexpr auto arr = std::array { ... }; where arr is not a local extern. The fix replaces the DECL_EXTERNAL check with DECL_THIS_EXTERN. DECL_THIS_EXTERN is set for local externs with initializers, and since consteval-only variables are effectively local externs, this change ensures they are correctly identified without interfering with oth…

For Context
C++ reflection
A metaprogramming feature that allows code to inspect and manipulate its own structure at compile time or runtime. In C++, this is a relatively new feature being standardized.
ICE
Internal Compiler Error. An unrecoverable error during compilation that indicates a bug in the compiler itself, rather than in the user's code.
consteval
A C++20 keyword that specifies a function or variable must produce a constant evaluated result at compile time. This is stricter than constexpr.
DECL_EXTERNAL
A GCC internal flag on a declaration (e.g., variable, function) indicating that it is defined elsewhere (e.g., in another compilation unit or library).
DECL_THIS_EXTERN
A GCC internal flag on a declaration indicating that it is an 'extern' declaration, often used for local extern variables that have initializers.
Filed Under: c++reflectioncompiler-bug