[PATCH] D71980: [clang-tidy] Disable Checks on If constexpr statements in template Instantiations for BugproneBranchClone and ReadabilityBracesAroundStatements

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 30 14:57:59 PST 2019


xazax.hun added a comment.

Thanks for working on this, please see one of my concerns inline.

If you are trying to fix this problem, alternatively, you could also fix it in Clang.

Richard outlined the best possible way to solve this class of errors by introducing a new type of AST node in: https://reviews.llvm.org/D46234



================
Comment at: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp:62
   Finder->addMatcher(
-      ifStmt(stmt().bind("if"),
+      ifStmt(unless(allOf(isConstexpr(), isInTemplateInstantiation())),
+             stmt().bind("if"),
----------------
Why do we care if we are inside a template instantiation? 

Couldn't we trigger the bug with something like:
```
void shouldPass() {
  if constexpr (constexprFun(1) == 0) {
    handle(0);
  } else if constexpr (constexprFun(1)  == 1) {
    handle(1);
  } else {
    handle(2);
  }
}
```

?


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

https://reviews.llvm.org/D71980





More information about the cfe-commits mailing list