Skip to content

Commit 0024875

Browse files
authored
[Clang] Raise an error on namespace aliases with qualified names. (#86122)
1 parent 7fc2fbb commit 0024875

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ Bug Fixes to C++ Support
437437
- Clang's __builtin_bit_cast will now produce a constant value for records with empty bases. See:
438438
(#GH82383)
439439
- Fix a crash when instantiating a lambda that captures ``this`` outside of its context. Fixes (#GH85343).
440+
- Fix an issue where a namespace alias could be defined using a qualified name (all name components
441+
following the first `::` were ignored).
440442

441443
Bug Fixes to AST Handling
442444
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ def err_expected_semi_after_namespace_name : Error<
268268
"expected ';' after namespace name">;
269269
def err_unexpected_namespace_attributes_alias : Error<
270270
"attributes cannot be specified on namespace alias">;
271+
def err_unexpected_qualified_namespace_alias : Error<
272+
"namespace alias must be a single identifier">;
271273
def err_unexpected_nested_namespace_attribute : Error<
272274
"attributes cannot be specified on a nested namespace definition">;
273275
def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ Parser::DeclGroupPtrTy Parser::ParseNamespace(DeclaratorContext Context,
140140
SkipUntil(tok::semi);
141141
return nullptr;
142142
}
143+
if (!ExtraNSs.empty()) {
144+
Diag(ExtraNSs.front().NamespaceLoc,
145+
diag::err_unexpected_qualified_namespace_alias)
146+
<< SourceRange(ExtraNSs.front().NamespaceLoc,
147+
ExtraNSs.back().IdentLoc);
148+
SkipUntil(tok::semi);
149+
return nullptr;
150+
}
143151
if (attrLoc.isValid())
144152
Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
145153
if (InlineLoc.isValid())

clang/test/SemaCXX/namespace-alias.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace I {
4747
namespace A1 { int i; }
4848

4949
namespace A2 = A1;
50+
51+
namespace A3::extra::specifiers = A2; // expected-error {{alias must be a single identifier}}
5052
}
5153

5254
int f() {

0 commit comments

Comments
 (0)