[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 09:22:38 PDT 2022


njames93 added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp:586
+
+  auto Not = hasOperatorName("!");
+  auto Or = hasOperatorName("||");
----------------
njames93 wrote:
> This whole implementation would be alot simpler(and likely faster) if you matched on the generic case then in the check callback work out what replacement you need.
> ```lang=c++
> Finder->addMatcher(
>     unaryOperator(
>         Not,
>         hasUnaryOperand(binaryOperator(
>             hasAnyOperatorName("&&", "||"),
>             hasEitherOperand(unaryOperator(Not))))).bind(Demorgan),
>     this);
> ```
Come to think of it, you wouldn't even need to work out which. Just remove the outer `!`, Exchange `||` with `&&` and invert each side of the binary operator.


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

https://reviews.llvm.org/D124650



More information about the cfe-commits mailing list