Skip to content

Commit 5c5e860

Browse files
committed
[clang-tidy] Fix PR35824
Differential Revision: https://reviews.llvm.org/D46027
1 parent b98a0c7 commit 5c5e860

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace bugprone {
2020
void SuspiciousSemicolonCheck::registerMatchers(MatchFinder *Finder) {
2121
Finder->addMatcher(
2222
stmt(anyOf(ifStmt(hasThen(nullStmt().bind("semi")),
23-
unless(hasElse(stmt()))),
23+
unless(hasElse(stmt())),
24+
unless(isConstexpr())),
2425
forStmt(hasBody(nullStmt().bind("semi"))),
2526
cxxForRangeStmt(hasBody(nullStmt().bind("semi"))),
2627
whileStmt(hasBody(nullStmt().bind("semi")))))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %check_clang_tidy %s bugprone-suspicious-semicolon %t -- -- -std=c++17
2+
3+
void fail()
4+
{
5+
int x = 0;
6+
if(x > 5); (void)x;
7+
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: potentially unintended semicolon [bugprone-suspicious-semicolon]
8+
// CHECK-FIXES: if(x > 5) (void)x;
9+
}
10+
11+
template <int X>
12+
int foo(int a) {
13+
if constexpr(X > 0) {
14+
return a;
15+
}
16+
return a + 1;
17+
}
18+
19+
template <int X>
20+
int foo2(int a) {
21+
// FIXME: diagnose the case below. See https://reviews.llvm.org/D46234
22+
// for details.
23+
if constexpr(X > 0);
24+
return a;
25+
return a + 1;
26+
}
27+
28+
int main(void) {
29+
foo2<0>(1);
30+
return foo<0>(1);
31+
}

0 commit comments

Comments
 (0)