Skip to content

Commit 1998809

Browse files
committed
Raise an error on namespace aliases with qualified names.
Current behavior is to ignore the trailing qualifiers, but the grammar for `namespace-alias-definition` requires an `identifier` without qualification. https://godbolt.org/z/1zvW5q4f8 https://eel.is/c++draft/namespace.alias#nt:namespace-alias-definition
1 parent 6eff53b commit 1998809

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

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+
"unexpected nested name specifier in namespace alias definition">;
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ Parser::DeclGroupPtrTy Parser::ParseNamespace(DeclaratorContext Context,
140140
SkipUntil(tok::semi);
141141
return nullptr;
142142
}
143+
if (!ExtraNSs.empty()) {
144+
Diag(IdentLoc, diag::err_unexpected_qualified_namespace_alias);
145+
SkipUntil(tok::semi);
146+
return nullptr;
147+
}
143148
if (attrLoc.isValid())
144149
Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
145150
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 {{unexpected nested name specifier}}
5052
}
5153

5254
int f() {

0 commit comments

Comments
 (0)