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

c++/reflection: Correct error for block-scope using [:ns:]::S.

Fixes a bogus error when using dependent namespaces with C++ reflection in block scopes.

This commit corrects an erroneous error message in C++ reflection when using dependent namespaces within a block scope, such as using [:ns:]::S; where ns is dependent. Previously, the compiler incorrectly reported that :: was not a class, namespace, or enumeration. The fix ensures that tsubst_stmt correctly handles NAMESPACE_DECL for dependent namespaces, which is necessary following the introduction of P2996.

In Details

Corrects an erroneous error message ('%qT is not a class, namespace, or enumeration') emitted by tsubst_stmt for DECL_EXPR involving dependent namespaces (e.g., using [:ns:]::S; where ns is a dependent namespace). The error occurred because tsubst did not account for NAMESPACE_DECL when MAYBE_CLASS_TYPE_P or ENUMERAL_TYPE checks failed, which is now required due to P2996 and dependent namespaces. The patch modifies tsubst_stmt to allow NAMESPACE_DECL and return error_mark_node appropriately.

For Context
C++ reflection
A proposed C++ feature (as of C++20) that allows code to inspect and manipulate types and entities at compile time, often using compile-time programming constructs.
dependent namespace
A namespace whose definition or existence depends on a template parameter, making its exact scope or members unknown until the template is instantiated.
block scope
The scope associated with a block of code, typically delimited by curly braces {}. Variables and declarations within a block are local to that block.
tsubst_stmt
A GCC internal function involved in template substitution and expression instantiation, processing statements during template expansion.
P2996
A C++ proposal (likely related to template metaprogramming or reflection) that introduced changes requiring better handling of dependent namespaces.
USING_DECL_TYPENAME_P
A GCC internal macro or function that checks if a using declaration refers to a type name, relevant in template and namespace contexts.
Filed Under: c++compilerreflectionbugfix