[PATCH] D124650: [clang-tidy] Simplify boolean expressions by DeMorgan's theorem

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 1 22:05:43 PDT 2022


njames93 added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:598-599
+  auto UnlessNotLHS = unless(hasLHS(NotOp));
+  // match !(!a || b)
+  Finder->addMatcher(unaryOperator(Not, hasUnaryOperand(binaryOperator(
+                                            Or, UnlessNotRHS, NotLHS, RHS)))
----------------
LegalizeAdulthood wrote:
> njames93 wrote:
> > Maybe I'm overthinking this, but how come you don't need the match on the ParenExpr?
> > Is there some traversal mode?
> How can you have a binaryOperator as the child of unaryOperator without parens?  The precedence doesn't allow it otherwise.
Its more the point that the AST has the ParenExpr
```lang=c++
!(a || !b);
```
```
`-UnaryOperator <col:12, col:21> 'bool' prefix '!' cannot overflow
  `-ParenExpr <col:13, col:21> 'bool'
    `-BinaryOperator <col:14, col:20> 'bool' '||'
      |-ImplicitCastExpr <col:14> 'bool' <LValueToRValue>
      | `-DeclRefExpr <col:14> 'bool' lvalue ParmVar 0x55a0e17465d0 'a' 'bool'
      `-UnaryOperator <col:19, col:20> 'bool' prefix '!' cannot overflow
        `-ImplicitCastExpr <col:20> 'bool' <LValueToRValue>
          `-DeclRefExpr <col:20> 'bool' lvalue ParmVar 0x55a0e1746648 'b' 'bool'
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124650/new/

https://reviews.llvm.org/D124650



More information about the cfe-commits mailing list