[PATCH] D130181: [clang-tidy] Add readability-use-early-exits check

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 29 06:41:50 PDT 2022


JonasToth added a comment.

just my 2 cents



================
Comment at: clang-tools-extra/clang-tidy/readability/UseEarlyExitsCheck.cpp:66
+  if (needsParensAfterUnaryNegation(Condition)) {
+    Diag << FixItHint::CreateInsertion(Condition->getBeginLoc(), "!(")
+         << FixItHint::CreateInsertion(
----------------
did you consider comma expressions?

`if (myDirtyCode(), myCondition && yourCondition)`. It seems to me, that the transformation would be incorrect.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability/use-early-exits.rst:55
+
+  If `true`, split up conditions with cunjunctions (``&&``) into multiple 
+  ``if`` statements. Default value is `false`.
----------------
typo `cunjunctions -> conjunctions`


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability/use-early-exits.rst:63
+    void Process(bool A, bool B) {
+      if (A && B) {
+        // Long processing.
----------------
if this option is false, the transformation would be `if(!(A && B))`, right?

should demorgan rules be applied or at least be mentioned here? I think transforming to `if (!A || !B)` is at least a viable option for enough users.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability/use-early-exits.rst:112
+
+  If `true`, the check will only report ifs which contain nested control blocks.
+  Default value is `false`
----------------
maybe highlight the `if` as code with double quotes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130181



More information about the cfe-commits mailing list