[PATCH] D47122: [clang-tidy] SimplifyBoolenExpr doesn't add parens if unary negotiation is of ExprWithCleanups type

Zinovy Nis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 10:28:24 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL333003: [clang-tidy] SimplifyBoolenExpr doesn't add parens if unary negotiation is of… (authored by zinovy.nis, committed by ).
Herald added subscribers: llvm-commits, klimek.

Changed prior to commit:
  https://reviews.llvm.org/D47122?vs=147836&id=148046#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47122

Files:
  clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp


Index: clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp
@@ -938,3 +938,13 @@
 }
 // CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
 // CHECK-FIXES: return p->m != 0;{{$}}
+
+bool operator!=(const A&, const A&) { return false; }
+bool expr_with_cleanups(A &S) {
+  if (S != (A)S)
+    return false;
+
+  return true;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: S == (A)S;{{$}}
Index: clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -195,6 +195,9 @@
 std::string replacementExpression(const MatchFinder::MatchResult &Result,
                                   bool Negated, const Expr *E) {
   E = E->ignoreParenBaseCasts();
+  if (const auto *EC = dyn_cast<ExprWithCleanups>(E))
+    E = EC->getSubExpr();
+
   const bool NeedsStaticCast = needsStaticCast(E);
   if (Negated) {
     if (const auto *UnOp = dyn_cast<UnaryOperator>(E)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47122.148046.patch
Type: text/x-patch
Size: 1421 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180522/2de51725/attachment.bin>


More information about the llvm-commits mailing list