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

C++ Reflection: Fixes Exception Handling in `extract_ref`

GCC now correctly throws exceptions in `extract_ref` when reflection encounters invalid array types, preventing internal compiler errors.

GCC now correctly throws an exception in the extract_ref function, a part of the C++ reflection implementation, when it encounters invalid array types (e.g., arrays of functions or methods). Previously, the code attempted to build arrays of these invalid types, leading to internal compiler errors (ICE). This fix ensures that the appropriate exception is thrown, providing more robust error handling during reflection.

In Details

This commit addresses PR125111 by modifying reflect.cc to throw an exception in extract_ref when dealing with arrays of functions, methods, or arrays with NULL_TYPE_DOMAIN. The code now avoids attempting to build these invalid array types, which previously caused ICEs. The fix specifically checks for these problematic cases and throws an exception when is_convertible_v<remove_reference_t<U>(*)[], remove_reference_t<T>(*)[]> is false.

For Context

Reflection allows a program to inspect and manipulate its own structure at runtime. In C++, this includes examining types, members, and other program elements. This commit fixes an error in the implementation of reflection where the compiler would crash when trying to reflect on code that involves creating arrays of invalid types (like arrays of functions). The fix ensures that a proper exception is generated in these cases, instead of crashing the compiler.

Filed Under: c++reflectionexceptionsbugfixcompiler error