[PATCH] D23243: [clang-tidy] enhance modernize-use-bool-literals to check ternary operator

Piotr Padlewski via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 6 18:44:16 PDT 2016


Prazek added inline comments.

================
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);
----------------
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.

================
Comment at: test/clang-tidy/modernize-use-bool-literals.cpp:119
@@ -118,1 +118,3 @@
 }
+
+static int Value = 1;
----------------
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);


Repository:
  rL LLVM

https://reviews.llvm.org/D23243





More information about the cfe-commits mailing list