Author: Mir Immad
Date: 2026-03-22T17:26:31+08:00
New Revision: a5472086ce24cd58b2f91381320b112511a12a27

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

LOG: [clang-tidy] False negatives readability-redundant-parantheses member of 
struct (#187054)

Fixes #186749

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
    
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
index bb993a60c9d4e..9b3948a1c50c0 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
@@ -54,7 +54,8 @@ void RedundantParenthesesCheck::registerMatchers(MatchFinder 
*Finder) {
       parenExpr(subExpr(anyOf(
                     parenExpr(), ConstantExpr,
                     declRefExpr(to(namedDecl(unless(
-                        
matchers::matchesAnyListedRegexName(AllowedDecls))))))),
+                        matchers::matchesAnyListedRegexName(AllowedDecls))))),
+                    memberExpr(), callExpr())),
                 unless(anyOf(isInMacro(),
                              // sizeof(...) is common used.
                              hasParent(unaryExprOrTypeTraitExpr()))))

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
index c77608c66469c..9a8a0d4d73483 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
@@ -71,3 +71,53 @@ void ignoreStdMaxMin() {
   (std::max)(1,2);
   (std::min)(1,2);
 }
+
+struct Foo
+{
+  bool x;
+  struct Y {
+    bool z;
+  } y;
+  void foo()
+  {
+   if ((x)) {
+     // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant parentheses around 
expression [readability-redundant-parentheses]
+     // CHECK-FIXES:    if (x) {
+   }
+   if((this->x)) {
+     // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around 
expression [readability-redundant-parentheses]
+     // CHECK-FIXES:    if(this->x) {
+   }
+  }
+  bool bar() {
+    return true;
+  }
+
+  Y fooBar() {
+    Y y{};
+    return y;
+  }
+};
+
+void memberExpr() {
+  Foo foo{};
+  if ((foo.x)) {
+   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around 
expression [readability-redundant-parentheses]
+   // CHECK-FIXES:    if (foo.x) {
+  }
+
+  if ((foo.y.z)) {
+   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around 
expression [readability-redundant-parentheses]
+   // CHECK-FIXES:    if (foo.y.z) {
+  }
+
+  if ((foo.bar())) {
+   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around 
expression [readability-redundant-parentheses]
+   // CHECK-FIXES:    if (foo.bar()) {
+  }
+
+  if ((foo.fooBar().z)) {
+   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around 
expression [readability-redundant-parentheses]
+   // CHECK-FIXES:    if (foo.fooBar().z) {
+  }
+}


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

Reply via email to