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

c++/reflection: Purge consteval-only variables before sanitizer checks

Fixes a compilation error when using reflection with sanitizers by purging consteval-only variables earlier.

A bug caused compilation failures when using C++ reflection features alongside sanitizers. Consteval-only variables were being processed too late, after sanitizer instrumentation had already attempted to generalize them. This led to errors, preventing constexpr functions from compiling correctly. This commit reorders operations to purge these variables before sanitizer checks, resolving the issue.

In Details

In GCC's C++ frontend, cp_genericize_r is responsible for transforming C++ constructs into GIMPLE. When handling BIND_EXPR nodes that represent consteval-only variables, this function previously performed the genericization after sanitizer-related checks. Sanitizer instrumentation, particularly for features like ASan or UBSan, might attempt to generalize these variables. If a variable is consteval-only, it cannot be generalized in a non-consteval context. This conflict could lead to a consteval function incorrectly escalating its evaluation context or a regular function failing to…

For Context
consteval
A C++20 keyword indicating that a function or constructor must produce a compile-time constant value. Its evaluation is guaranteed to happen at compile time.
reflection
In C++, compile-time reflection allows code to inspect and manipulate its own structure (like types and members) during compilation, often used with features like concepts and templates.
GIMPLE
GCC's internal representation for intermediate code, used after parsing and high-level transformations, before machine-specific code generation.
sanitizer
Tools like AddressSanitizer (ASan) or UndefinedBehaviorSanitizer (UBSan) that instrument code during compilation to detect memory errors or undefined behavior at runtime.
Filed Under: c++reflectioncompiler