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

Disallow reflection on block-scope extern declarations in C++.

The C++ reflection feature now forbids reflecting on block-scope extern declarations, aligning with the CWG 3065 resolution and fixing a crash.

This patch enforces a restriction on C++ reflection, disallowing reflection on block-scope extern declarations, as suggested by CWG issue 3065. This change not only aligns the compiler with the C++ standard but also fixes a crash that could occur when attempting such reflections. The patch adds error handling to prevent reflection of block-scope externs.

In Details

This commit modifies reflect.cc to introduce a check in get_reflection that flags attempts to reflect on block-scope extern declarations as errors. This aligns with the proposed resolution of CWG 3065, which deems such reflections ill-formed. The change also resolves a crash scenario associated with this disallowed operation. This area of the compiler interacts with the broader C++ reflection implementation, specifically how the compiler represents and manipulates reflected entities.

For Context

C++ reflection is a feature that allows programs to introspect and manipulate their own structure at compile time. This includes querying information about types, classes, and functions. 'Extern' declarations declare a variable without defining it, indicating that its storage is allocated elsewhere, often in another compilation unit. 'Block scope' refers to declarations within a function or block of code. This commit restricts reflection on extern variables declared inside functions, as the standard committee has deemed such operations problematic. Restricting this behavior helps ensure the correctness and stability of the reflection mechanism.

Filed Under: c++reflectionstandard