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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 7 12:08:13 PDT 2016


aaron.ballman added a comment.

Would it also make sense to support `BinaryConditionalOperator` as well as the ternary operator?


================
Comment at: clang-tidy/modernize/UseBoolLiteralsCheck.cpp:51-52
@@ -34,4 +50,4 @@
 void UseBoolLiteralsCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *Literal = Result.Nodes.getNodeAs<IntegerLiteral>("literal");
-  const auto *Cast = Result.Nodes.getNodeAs<Expr>("cast");
-  bool LiteralBooleanValue = Literal->getValue().getBoolValue();
+  for (const auto &BindingName :
+       {"literal", "trueBranchLiteral", "falseBranchLiteral"}) {
+    const auto *Literal = Result.Nodes.getNodeAs<IntegerLiteral>(BindingName);
----------------
Any reason not to name the bind "literal" in all three cases? That eliminates the need for the loop entirely, since `check()` will trigger for each instance of a match.


https://reviews.llvm.org/D23243





More information about the cfe-commits mailing list