Abpostelnicu updated this revision to Diff 236580.
Abpostelnicu added a comment.
Updated the test case to better reflect the changes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72333/new/
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,52 @@
#pragma unroll
for (int k = 0; k < 1; ++k) {}
}
+
+template<bool b>
+void mustPass() {
+ if constexpr (b) {
+ foo1();
+ } else {
+ foo2();
+ }
+}
+
+void mustPassNonTemplate() {
+ constexpr unsigned Value = 1;
+ if constexpr (Value == 0) {
+ foo1();
+ } else if constexpr (Value == 1) {
+ foo2();
+ } else {
+ foo3();
+ }
+}
+
+template<bool b>
+void mustFail() {
+ if constexpr (b) {
+ foo1();
+ }
+ else {
+ foo2();
+ // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for
'if' and corresponding 'else' [readability-misleading-indentation]
+ }
+}
+
+void mustFailNonTemplate() {
+ constexpr unsigned Value = 1;
+ if constexpr (Value == 0) {
+ foo1();
+ }
+ else {
+ foo2();
+ // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if'
and corresponding 'else' [readability-misleading-indentation]
+ }
+}
+
+void call() {
+ mustPass<true>();
+ mustPass<false>();
+ mustFail<true>();
+ mustFail<false>();
+}
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"),
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,52 @@
#pragma unroll
for (int k = 0; k < 1; ++k) {}
}
+
+template<bool b>
+void mustPass() {
+ if constexpr (b) {
+ foo1();
+ } else {
+ foo2();
+ }
+}
+
+void mustPassNonTemplate() {
+ constexpr unsigned Value = 1;
+ if constexpr (Value == 0) {
+ foo1();
+ } else if constexpr (Value == 1) {
+ foo2();
+ } else {
+ foo3();
+ }
+}
+
+template<bool b>
+void mustFail() {
+ if constexpr (b) {
+ foo1();
+ }
+ else {
+ foo2();
+ // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+ }
+}
+
+void mustFailNonTemplate() {
+ constexpr unsigned Value = 1;
+ if constexpr (Value == 0) {
+ foo1();
+ }
+ else {
+ foo2();
+ // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+ }
+}
+
+void call() {
+ mustPass<true>();
+ mustPass<false>();
+ mustFail<true>();
+ mustFail<false>();
+}
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"),
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits