[PATCH] D23243: [clang-tidy] enhance modernize-use-bool-literals to check ternary operator
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 7 02:00:34 PDT 2016
omtcyfz marked 2 inline comments as done.
================
Comment at: clang-tidy/modernize/UseBoolLiteralsCheck.cpp:38-43
@@ +37,8 @@
+ unless(isInTemplateInstantiation()))),
+ anyOf(hasTrueExpression(ignoringParenImpCasts(
+ integerLiteral().bind("trueBranchLiteral"))),
+ anything()),
+ anyOf(hasFalseExpression(ignoringParenImpCasts(
+ integerLiteral().bind("falseBranchLiteral"))),
+ anything())),
+ this);
----------------
Prazek wrote:
> Do I understand it correctly, that you have to have this 2 anyOf matchers, because if you would have it in one then because anyOf is lazy, it would not bind to the second branch?
>
> I think it would be good to write some comment about it, because on the first sight it looks like it could be simplified.
> Do I understand it correctly, that you have to have this 2 anyOf matchers, because if you would have it in one then because anyOf is lazy, it would not bind to the second branch?
Yes, exactly. In order to bind both I do `anyOf()`.
> I think it would be good to write some comment about it, because on the first sight it looks like it could be simplified.
Done.
================
Comment at: test/clang-tidy/modernize-use-bool-literals.cpp:119
@@ -118,1 +118,3 @@
}
+
+static int Value = 1;
----------------
Prazek wrote:
> Please add a test with only one branch with constant, and none of them.
> Also one test like
> bool Result = Value == 1 ? true : 0;
> or
> bool Result = Value == 1 ? false : bool(0);
Added a bunch of new tests.
https://reviews.llvm.org/D23243
More information about the cfe-commits
mailing list