Author: Zeyi Xu
Date: 2026-09-07T19:33:09+08:00
New Revision: cd3a2657c7193abbdba4620649ff5b8f7409e47a

URL: 
https://github.com/llvm/llvm-project/commit/cd3a2657c7193abbdba4620649ff5b8f7409e47a
DIFF: 
https://github.com/llvm/llvm-project/commit/cd3a2657c7193abbdba4620649ff5b8f7409e47a.diff

LOG: [clang-tidy] Fix bugprone-macro-parentheses false positives for alias 
names (#219955)

Fixes #219922.

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
    clang-tools-extra/docs/ReleaseNotes.md
    clang-tools-extra/test/clang-tidy/checkers/bugprone/macro-parentheses.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
index a51bce1484a42..1de723cb87b5b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
@@ -53,7 +53,7 @@ static bool isSurroundedRight(const Token &T) {
 static bool isKeyword(const Token &T) {
   // FIXME: better matching of keywords to avoid false positives.
   return T.isOneOf(tok::kw_if, tok::kw_case, tok::kw_const, tok::kw_volatile,
-                   tok::kw_struct);
+                   tok::kw_struct, tok::kw_using);
 }
 
 /// Warning is written when one of these operators are not within parentheses.

diff  --git a/clang-tools-extra/docs/ReleaseNotes.md 
b/clang-tools-extra/docs/ReleaseNotes.md
index b32b8a51e0606..4523e0f78035b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -146,6 +146,10 @@ infrastructure are described first, followed by 
tool-specific sections.
   instead of forcing a signed type, when a multiplication of two unsigned
   operands narrower than `int` is only signed due to integer promotion.
 
+- Improved {doc}`bugprone-macro-parentheses
+  <clang-tidy/checks/bugprone/macro-parentheses>` by fixing invalid fixes for
+  macro arguments used as names in alias declarations.
+
 - Fixed a crash in {doc}`bugprone-misplaced-operator-in-strlen-in-alloc
   <clang-tidy/checks/bugprone/misplaced-operator-in-strlen-in-alloc>` when
   checking an array new expression without a size expression.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/macro-parentheses.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/macro-parentheses.cpp
index a3ce47d3d0885..3900801adb362 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/macro-parentheses.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/macro-parentheses.cpp
@@ -14,6 +14,8 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: macro argument should be enclosed 
in parentheses [bugprone-macro-parentheses]
 #define BAD7(x, y)        if (x) goto y; else x;
 // CHECK-MESSAGES: :[[@LINE-1]]:47: warning: macro argument should be enclosed 
in parentheses [bugprone-macro-parentheses]
+#define BAD8(name, x)     using name = decltype(x + 1)
+// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: macro argument should be enclosed 
in parentheses
 
 #define GOOD1             1
 #define GOOD2             (1+2)
@@ -51,6 +53,14 @@
 #define GOOD34(x, y)      if (x) goto y;
 #define GOOD35(x, y)      if (x) goto *(y);
 
+struct something {};
+#define GOOD36(name)      using name = something
+#define GOOD37(name)      using name = something &
+#define GOOD38(name)      using name = decltype(#name)
+GOOD36(foo);
+GOOD37(bar);
+GOOD38(baz);
+
 // These are allowed for now..
 #define MAYBE1            *12.34
 #define MAYBE2            <<3


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

Reply via email to