[clang-tools-extra] r333003 - [clang-tidy] SimplifyBoolenExpr doesn't add parens if unary negotiation is of ExprWithCleanups type
Zinovy Nis via cfe-commits
cfe-commits at lists.llvm.org
Tue May 22 10:24:28 PDT 2018
Author: zinovy.nis
Date: Tue May 22 10:24:28 2018
New Revision: 333003
URL: http://llvm.org/viewvc/llvm-project?rev=333003&view=rev
Log:
[clang-tidy] SimplifyBoolenExpr doesn't add parens if unary negotiation is of ExprWithCleanups type
bool foo(A &S) {
if (S != (A)S)
return false;
return true;
}
is fixed into (w/o this patch)
...
return !S != (A)S; // negotiation affects first operand only
}
instead of (with this patch)
...
return S == (A)S; // note == instead of !=
}
Differential Revision: https://reviews.llvm.org/D47122
Modified:
clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp
Modified: clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp?rev=333003&r1=333002&r2=333003&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp Tue May 22 10:24:28 2018
@@ -195,6 +195,9 @@ std::string compareExpressionToZero(cons
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)) {
Modified: clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp?rev=333003&r1=333002&r2=333003&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp Tue May 22 10:24:28 2018
@@ -938,3 +938,13 @@ bool integer_member_implicit_cast(A *p)
}
// 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;{{$}}
More information about the cfe-commits
mailing list