-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Raise an error on namespace aliases with qualified names. #86122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-testing-tools @llvm/pr-subscribers-clang Author: Daniel M. Katz (katzdm) ChangesClang's current behavior is to ignore the trailing qualifiers, but the grammar for https://godbolt.org/z/1zvW5q4f8 Full diff: https://github.com/llvm/llvm-project/pull/86122.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 816c3ff5f8b2aa..d45a1f0b6ad1c0 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -268,6 +268,8 @@ def err_expected_semi_after_namespace_name : Error<
"expected ';' after namespace name">;
def err_unexpected_namespace_attributes_alias : Error<
"attributes cannot be specified on namespace alias">;
+def err_unexpected_qualified_namespace_alias : Error<
+ "unexpected nested name specifier in namespace alias definition">;
def err_unexpected_nested_namespace_attribute : Error<
"attributes cannot be specified on a nested namespace definition">;
def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 77d2382ea6d907..0ef2f2fad2a9d1 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -140,6 +140,11 @@ Parser::DeclGroupPtrTy Parser::ParseNamespace(DeclaratorContext Context,
SkipUntil(tok::semi);
return nullptr;
}
+ if (!ExtraNSs.empty()) {
+ Diag(IdentLoc, diag::err_unexpected_qualified_namespace_alias);
+ SkipUntil(tok::semi);
+ return nullptr;
+ }
if (attrLoc.isValid())
Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
if (InlineLoc.isValid())
diff --git a/clang/test/SemaCXX/namespace-alias.cpp b/clang/test/SemaCXX/namespace-alias.cpp
index 281ee9962e8b52..10d2e8beeccaa0 100644
--- a/clang/test/SemaCXX/namespace-alias.cpp
+++ b/clang/test/SemaCXX/namespace-alias.cpp
@@ -47,6 +47,8 @@ namespace I {
namespace A1 { int i; }
namespace A2 = A1;
+
+ namespace A3::extra::specifiers = A2; // expected-error {{unexpected nested name specifier}}
}
int f() {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing! This needs a release note (in clang/docs/ReleaseNotes.rst
) and some changes to the diagnostics, but other than that it looks fine to me.
@Sirraide Thanks for the quick review! I've applied your feedback. Here is an example error message with the patch applied:
Oops, still need the release note. |
Nice, that is pretty much exactly what I had in mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for a minor comment wrt the release note.
You can ignore the merge conflicts in the release notes; it’s better to let whoever ends up merging this (probably me) take care of that when it comes to the release notes (because they get updated constantly). |
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
✅ With the latest revision this PR passed the Python code formatter. |
c5997ee
to
3c6632e
Compare
Ah, missed this - already fixed it. Will ignore if it happens again. |
I mean, no-one’s gonna be mad at you for fixing that yourself because it means less work for them; just saying that merging release notes is fairly trivial, so whoever merges it can just do that when they merge the pr—at least that’s my opinion on this. Otherwise, you’d have to keep resolving merge conflicts because they might come back time and time again if a pr stays open for a while. |
@katzdm Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Clang's current behavior is to ignore the trailing qualifiers, but the grammar for
namespace-alias-definition
requires anidentifier
without qualification.https://godbolt.org/z/1zvW5q4f8