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

C++/reflection: Detect more invalid splice-expressions

Compiler now correctly rejects invalid template usage in C++20 reflection splice expressions.

GCC’s C++ reflection support now correctly detects more invalid uses of splice-expressions, specifically addressing issues with template usage. The compiler previously crashed or miscompiled code where templates were incorrectly used in splice-specifiers or template splice-specializations. This fix aligns the compiler with C++20 standard sections [expr.prim.splice]/2 and /4, improving diagnostics and preventing crashes, while also extending error checking for dependent splices.

In Details

This commit refines the C++20 reflection implementation by improving the validation of splice-expr syntax, particularly concerning templates. It rectifies check_splice_expr in reflect.cc to correctly reject non-function/variable templates in splice-specifier contexts, aligning with [expr.prim.splice]/2. Additionally, it enforces the restriction that only function and variable templates are allowed in template-splice-specialization-specifier, per [expr.prim.splice]/4. The changes also fix missing_template_diag for dependent splices, enhancing diagnostic messages.

For Context
C++ reflection
A proposed C++ feature (standardized in C++26, with earlier experimental support) that allows code to inspect and manipulate its own structure at compile time. This includes examining types, members, and templates.
splice-expression
A construct within C++20's reflection facilities that allows for the inclusion or exclusion of members or bases from a reflected entity, often used to conditionally add or remove members during template instantiation.
template
A blueprint for creating classes or functions in C++. Templates allow code to be written generically, working with different types without explicit duplication.
dependent splice
A splice-expression whose evaluation or validity depends on a template parameter that is not yet known. Diagnosing errors in these constructs can be complex.
ABI
Application Binary Interface. Defines how low-level code is structured, including function calling conventions, data layout, and name mangling. Incorrect ABI compliance can lead to runtime errors.
Filed Under: c++reflectiondiagnosticsc++20