https://github.com/zeyi2 updated 
https://github.com/llvm/llvm-project/pull/219955

>From a5433cfdbb40cfc285001f50fef7dd22ae4f8b88 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <[email protected]>
Date: Mon, 31 Aug 2026 20:04:01 +0800
Subject: [PATCH] [clang-tidy] Fix bugprone-macro-parentheses false positives
 for alias names

---
 .../clang-tidy/bugprone/MacroParenthesesCheck.cpp      |  2 +-
 clang-tools-extra/docs/ReleaseNotes.md                 |  4 ++++
 .../clang-tidy/checkers/bugprone/macro-parentheses.cpp | 10 ++++++++++
 3 files changed, 15 insertions(+), 1 deletion(-)

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 51dd99256ca69..67f05ea31243b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -124,6 +124,10 @@ infrastructure are described first, followed by 
tool-specific sections.
 
 #### Changes in existing checks
 
+- 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