[PATCH] D72333: [clang-tidy] Disable match on `if constexpr` statements in template instantiation for `readability-misleading-indentation` check.
Andi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 7 06:37:08 PST 2020
Abpostelnicu created this revision.
Abpostelnicu added a reviewer: alexfh.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
Fixes fixes `readability-misleading-identation` for `if constexpr`. This is very similar to D71980 <https://reviews.llvm.org/D71980>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72333
Files:
clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -2,6 +2,7 @@
void foo1();
void foo2();
+void foo3();
#define BLOCK \
if (cond1) \
@@ -118,3 +119,14 @@
#pragma unroll
for (int k = 0; k < 1; ++k) {}
}
+
+void shouldPassNoTemplate() {
+ constexpr unsigned Value = 1;
+ if constexpr (Value == 0) {
+ foo1();
+ } else if constexpr (Value == 1) {
+ foo2();
+ } else {
+ foo3();
+ }
+}
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -106,7 +106,11 @@
}
void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+ Finder->addMatcher(
+ ifStmt(allOf(hasElse(stmt()),
+ unless(allOf(isConstexpr(), isInTemplateInstantiation()))))
+ .bind("if"),
+ this);
Finder->addMatcher(
compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()))))
.bind("compound"),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72333.236575.patch
Type: text/x-patch
Size: 1462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200107/ed26ecce/attachment.bin>
More information about the cfe-commits
mailing list