[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 2 23:21:17 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tidy

Author: Andre Sun (and2049)

<details>
<summary>Changes</summary>

Skip synthetic parentheses with identical source locations in
`readability-redundant-parentheses`. This also stops
`__builtin_dump_struct(&s, printf)` from being rewritten to `(&s, printf)`
and stops variables being deleted from OpenMP `linear` clauses.

Fixes #<!-- -->224705.

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp (+2) 
- (added) clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp (+8) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp (+14) 


``````````diff
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
index bc1d10586da8ab..75a11ffc02503b 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
@@ -93,6 +93,8 @@ void RedundantParenthesesCheck::registerMatchers(MatchFinder *Finder) {
 
 void RedundantParenthesesCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *PE = Result.Nodes.getNodeAs<ParenExpr>("dup");
+  if (PE->getLParen() == PE->getRParen())
+    return;
   diag(PE->getBeginLoc(), "redundant parentheses around expression")
       << createSpacedRemoval(PE->getLParen(), *Result.SourceManager,
                              getLangOpts())
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp
new file mode 100644
index 00000000000000..98e9c36fb0a863
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp
@@ -0,0 +1,8 @@
+// RUN: %check_clang_tidy %s readability-redundant-parentheses %t -- -- -fopenmp=libomp
+
+void linearClause(int *a, int n) {
+  int i = 0;
+#pragma omp simd linear(i)
+  for (int k = 0; k < n; ++k)
+    a[k] = i;
+}
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 c6275be9f24988..12286cd513f853 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
@@ -74,6 +74,20 @@ void ignoreStdMaxMin() {
   (std::min)(1,2);
 }
 
+int global = 0;
+template <int &R> int &referenceTemplateArgument() {
+  return R;
+}
+int &useReferenceTemplateArgument() {
+  return referenceTemplateArgument<global>();
+}
+
+extern "C" int printf(const char *, ...);
+struct Dumped { int x; };
+void dumpStruct(Dumped *d) {
+  __builtin_dump_struct(d, printf);
+}
+
 struct Foo
 {
   bool x;

``````````

</details>


https://github.com/llvm/llvm-project/pull/228666


More information about the cfe-commits mailing list