https://github.com/katzdm updated https://github.com/llvm/llvm-project/pull/86122
>From 319b7d99b4010514a1680ffd99fb0586b5e7221d Mon Sep 17 00:00:00 2001 From: Dan Katz <kat...@gmail.com> Date: Thu, 21 Mar 2024 09:47:04 -0400 Subject: [PATCH 1/4] 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 --- clang/include/clang/Basic/DiagnosticParseKinds.td | 2 ++ clang/lib/Parse/ParseDeclCXX.cpp | 5 +++++ clang/test/SemaCXX/namespace-alias.cpp | 2 ++ 3 files changed, 9 insertions(+) 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() { >From d28b8e1f6782f69e2c49151cae1d9898f331f0b9 Mon Sep 17 00:00:00 2001 From: Dan Katz <kat...@gmail.com> Date: Thu, 21 Mar 2024 11:44:03 -0400 Subject: [PATCH 2/4] Addressing feedback. --- clang/include/clang/Basic/DiagnosticParseKinds.td | 2 +- clang/lib/Parse/ParseDeclCXX.cpp | 5 ++++- clang/test/SemaCXX/namespace-alias.cpp | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index d45a1f0b6ad1c0..6290a08fcf4d3b 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -269,7 +269,7 @@ def err_expected_semi_after_namespace_name : Error< 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">; + "namespace alias must be a single identifier">; 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 0ef2f2fad2a9d1..63fe678cbb29e2 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -141,7 +141,10 @@ Parser::DeclGroupPtrTy Parser::ParseNamespace(DeclaratorContext Context, return nullptr; } if (!ExtraNSs.empty()) { - Diag(IdentLoc, diag::err_unexpected_qualified_namespace_alias); + Diag(ExtraNSs.front().NamespaceLoc, + diag::err_unexpected_qualified_namespace_alias) + << SourceRange(ExtraNSs.front().NamespaceLoc, + ExtraNSs.back().IdentLoc); SkipUntil(tok::semi); return nullptr; } diff --git a/clang/test/SemaCXX/namespace-alias.cpp b/clang/test/SemaCXX/namespace-alias.cpp index 10d2e8beeccaa0..591957a657c03a 100644 --- a/clang/test/SemaCXX/namespace-alias.cpp +++ b/clang/test/SemaCXX/namespace-alias.cpp @@ -48,7 +48,7 @@ namespace I { namespace A2 = A1; - namespace A3::extra::specifiers = A2; // expected-error {{unexpected nested name specifier}} + namespace A3::extra::specifiers = A2; // expected-error {{alias must be a single identifier}} } int f() { >From 61e85be30f4015826343a7253b339318392d9b69 Mon Sep 17 00:00:00 2001 From: Dan Katz <kat...@gmail.com> Date: Thu, 21 Mar 2024 11:57:18 -0400 Subject: [PATCH 3/4] Add release notes. --- clang/docs/ReleaseNotes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 125d51c42d507f..7f63835d6e075f 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -394,6 +394,8 @@ Bug Fixes to C++ Support expression references to an entity declared outside of the lambda. (#GH64808) - Clang's __builtin_bit_cast will now produce a constant value for records with empty bases. See: (#GH82383) +- Fix an issue where a namespace alias could be defined using a qualified name (all name components +following the first `::` were ignored). (#GH86122) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ >From c5997eedca3ada4c1d644ad41159933c3b8da051 Mon Sep 17 00:00:00 2001 From: Dan Katz <kat...@gmail.com> Date: Thu, 21 Mar 2024 12:35:43 -0400 Subject: [PATCH 4/4] Fix release note. --- clang/docs/ReleaseNotes.rst | 2 +- llvm/utils/lit/lit/formats/googletest.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7f63835d6e075f..14c75e6bc9a088 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -395,7 +395,7 @@ Bug Fixes to C++ Support - Clang's __builtin_bit_cast will now produce a constant value for records with empty bases. See: (#GH82383) - Fix an issue where a namespace alias could be defined using a qualified name (all name components -following the first `::` were ignored). (#GH86122) +following the first `::` were ignored). Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/llvm/utils/lit/lit/formats/googletest.py b/llvm/utils/lit/lit/formats/googletest.py index 8037094a910678..6c6e48a3a179fd 100644 --- a/llvm/utils/lit/lit/formats/googletest.py +++ b/llvm/utils/lit/lit/formats/googletest.py @@ -33,6 +33,7 @@ def get_num_tests(self, path, litConfig, localConfig): [path, "--gtest_list_tests", "--gtest_filter=-*DISABLED_*"] ) try: + localConfig.environment['DYLD_LIBRARY_PATH'] = '' out = subprocess.check_output(list_test_cmd, env=localConfig.environment) except subprocess.CalledProcessError as exc: litConfig.warning( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits