Index: clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp =================================================================== --- clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp +++ clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp @@ -45,12 +45,15 @@ unsigned SemicolonLine = SM.getSpellingLineNumber(LocStart); const auto *Statement = Result.Nodes.getNodeAs("stmt"); - const bool IsIfStmt = isa(Statement); + const auto *IfNode = dyn_cast(Statement); - if (!IsIfStmt && + if (!IfNode && SM.getSpellingLineNumber(Token.getLocation()) != SemicolonLine) return; + if (IfNode && IfNode->isConstexpr()) + return; + SourceLocation LocEnd = Semicolon->getLocEnd(); FileID FID = SM.getFileID(LocEnd); llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, LocEnd); @@ -64,7 +67,7 @@ unsigned NewTokenIndent = SM.getSpellingColumnNumber(Token.getLocation()); unsigned NewTokenLine = SM.getSpellingLineNumber(Token.getLocation()); - if (!IsIfStmt && NewTokenIndent <= BaseIndent && + if (!IfNode && NewTokenIndent <= BaseIndent && Token.getKind() != tok::l_brace && NewTokenLine != SemicolonLine) return; Index: test/clang-tidy/bugprone-suspicious-semicolon-constexpr.cpp =================================================================== --- /dev/null +++ test/clang-tidy/bugprone-suspicious-semicolon-constexpr.cpp @@ -0,0 +1,21 @@ +// RUN: %check_clang_tidy %s bugprone-suspicious-semicolon %t -- -- -std=c++17 + +void fail() +{ + int x = 0; + if(x > 5); (void)x; + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: potentially unintended semicolon [bugprone-suspicious-semicolon] + // CHECK-FIXES: if(x > 5) (void)x; +} + +template +int foo(int a) { + if constexpr(X > 0) { + return a; + } + return a + 1; +} + +int main(void) { + return foo<0>(1); +}