Fix C++ reflection to correctly handle spliced namespaces in using directives.
C++ reflection now correctly handles spliced namespaces in using directives, fixing a bug that prevented certain namespace usages.
This commit addresses a bug in C++ reflection where spliced namespaces in using directives were not correctly detected or handled. Previously, the compiler would incorrectly consider the global namespace as dependent, leading to failures in using directives like ‘using namespace ::’ or ‘using namespace std::’. The fix adjusts the type_dependent_expression_p function to correctly identify non-dependent namespaces, enabling these directives to work as expected and aligning with C++ standards regarding namespace splicing.
In Details
The change in gcc/cp/pt.cc modifies type_dependent_expression_p to return false for NAMESPACE_DECL. This affects how C++ reflection handles namespace splicing in using directives, specifically for cases involving global or qualified namespaces. Previously, global_namespace was incorrectly treated as dependent due to its initial void_type_node, causing issues with constructs like using namespace ::N;. This commit ensures compliance with [namespace.udir]/1 and [namespace.alias]/2 by correctly identifying dependent vs. non-dependent namespaces, particularly when global_namespace'…
- spliced namespace
- A namespace that is merged with another namespace, typically for organizational purposes. In C++, this refers to using directives that incorporate namespaces, potentially leading to name clashes or ambiguities if not handled correctly by the compiler.
- using directive
- A C++ construct (e.g.,
using namespace ...;) that brings all names from a namespace into the current scope, making them accessible without qualification. - dependent expression
- In the context of C++ templates, an expression whose evaluation depends on template parameters. Such expressions cannot be fully evaluated until the template is instantiated.
- namespace splicing
- The C++ mechanism that allows the declaration of a namespace to be split across multiple definitions, effectively merging them into a single logical namespace.