https://github.com/AlexsanderDamaceno updated 
https://github.com/llvm/llvm-project/pull/223910

>From a958c3812a94b797e89c088731eba91eb2d320ce Mon Sep 17 00:00:00 2001
From: AlexsanderDamaceno <[email protected]>
Date: Wed, 16 Sep 2026 01:04:36 -0300
Subject: [PATCH] For [[maybe_unused]] written before the 'using' keyword of an
 alias-declaration:

[[maybe_unused]] using T = int;

Clang currently reports only:

error: an attribute list cannot appear here

with no indication of where the attribute should actually go

Parser::DiagnoseProhibitedAttributes already provides exactly this behavior,
emitting a more helpful fix-it that suggests moving the attribute to the 
correct location.
ParseUsingDeclaration already uses it without pass the FixItLoc
location this way the fix-it sugestion is not show for using decl.

This patch passes the right location when the attribute is [[maybe_unused]], 
making the fix-it appear for the user.

Improvement suggestion link: #155787
---
 clang/docs/ReleaseNotes.md                     | 3 +++
 clang/lib/Parse/ParseDeclCXX.cpp               | 2 +-
 clang/test/Parser/cxx0x-attributes.cpp         | 6 +++++-
 clang/test/Parser/cxx0x-keyword-attributes.cpp | 2 +-
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 9063e54b3e692..558dc191a4ffb 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -758,6 +758,9 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
 - Fixed missing sentinel attribute diagnostic discrepancy with explicit object
   parameters in variadic functions. (#GH200007)
 
+- Suggests the correct location for an attribute written before the `using`
+  keyword of an alias-declaration. (#GH155787)
+
 ### Improvements to Clang's time-trace
 
 ### Improvements to Coverage Mapping
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 893989bd2398f..597078686e815 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -749,7 +749,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration(
       return nullptr;
     }
 
-    ProhibitAttributes(PrefixAttrs);
+    ProhibitAttributes(PrefixAttrs, Tok.getLocation());
 
     Decl *DeclFromDeclSpec = nullptr;
     Scope *CurScope = getCurScope();
diff --git a/clang/test/Parser/cxx0x-attributes.cpp 
b/clang/test/Parser/cxx0x-attributes.cpp
index 220fddb98127a..a2fb69fa3270d 100644
--- a/clang/test/Parser/cxx0x-attributes.cpp
+++ b/clang/test/Parser/cxx0x-attributes.cpp
@@ -181,7 +181,7 @@ void bad_attributes_in_do_while() {
                        // expected-error@-1 {{expected ';' after do/while}}
 } // expected-error 2{{expected ')'}} expected-error {{expected expression}}
 
-[[]] using T = int; // expected-error {{an attribute list cannot appear here}}
+[[]] using T = int; // expected-error {{misplaced attributes; expected 
attributes here}}
 using T [[]] = int; // ok
 template<typename T> using U [[]] = T;
 using ns::i [[]];
@@ -200,6 +200,10 @@ using T [[noreturn]] = int; // expected-error {{'noreturn' 
attribute only applie
 using V = int; // expected-note {{previous}}
 using V [[gnu::vector_size(16)]] = int; // expected-error {{redefinition with 
different types}}
 
+void using_alias_in_block() {
+  [[maybe_unused]] using BlockAlias = int; // expected-error {{misplaced 
attributes; expected attributes here}}
+}
+
 auto trailing() -> [[]] const int; // expected-error {{an attribute list 
cannot appear here}}
 auto trailing() -> const [[]] int; // expected-error {{an attribute list 
cannot appear here}}
 auto trailing() -> const int [[]];
diff --git a/clang/test/Parser/cxx0x-keyword-attributes.cpp 
b/clang/test/Parser/cxx0x-keyword-attributes.cpp
index e044336eb1792..72e2a90195ee1 100644
--- a/clang/test/Parser/cxx0x-keyword-attributes.cpp
+++ b/clang/test/Parser/cxx0x-keyword-attributes.cpp
@@ -139,7 +139,7 @@ using ATTR_USE alignas(4) ATTR_USE foobar = int; // 
expected-error {{'ATTR_NAME'
                                                                   
expected-error {{'alignas' attribute only applies to}} \
                                                                   
expected-error 2 {{'ATTR_NAME' only applies to function types}}
 
-ATTR_USE using T = int; // expected-error {{'ATTR_NAME' cannot appear here}}
+ATTR_USE using T = int; // expected-error {{misplaced 'ATTR_NAME'; expected 
'ATTR_NAME' here}}
 using T ATTR_USE = int; // expected-error {{'ATTR_NAME' only applies to 
function types}}
 template<typename T> using U ATTR_USE = T; // expected-error {{'ATTR_NAME' 
only applies to function types}}
 using ns::i ATTR_USE; // expected-warning {{ISO C++}} \

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to