llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Alexsander Borges Damaceno (AlexsanderDamaceno)

<details>
<summary>Changes</summary>

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:  https://github.com/llvm/llvm-project/issues/155787

---
Full diff: https://github.com/llvm/llvm-project/pull/223910.diff


2 Files Affected:

- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+4-1) 
- (modified) clang/test/Parser/cxx0x-attributes.cpp (+4) 


``````````diff
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 893989bd2398f..c9d133f5e341c 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -749,7 +749,10 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration(
       return nullptr;
     }
 
-    ProhibitAttributes(PrefixAttrs);
+    SourceLocation MisplacedAttrFixItLoc;
+    if (PrefixAttrs.hasAttribute(ParsedAttr::AT_Unused))
+      MisplacedAttrFixItLoc = Tok.getLocation();
+    ProhibitAttributes(PrefixAttrs, MisplacedAttrFixItLoc);
 
     Decl *DeclFromDeclSpec = nullptr;
     Scope *CurScope = getCurScope();
diff --git a/clang/test/Parser/cxx0x-attributes.cpp 
b/clang/test/Parser/cxx0x-attributes.cpp
index 220fddb98127a..2f3329d558dca 100644
--- a/clang/test/Parser/cxx0x-attributes.cpp
+++ b/clang/test/Parser/cxx0x-attributes.cpp
@@ -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 [[]];

``````````

</details>


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

Reply via email to