xazax.hun updated this revision to Diff 231078. xazax.hun added a comment. Herald added subscribers: Charusso, gamesh411.
- Use matcher. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D46027/new/ https://reviews.llvm.org/D46027 Files: clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp clang-tools-extra/test/clang-tidy/bugprone-suspicious-semicolon-constexpr.cpp Index: clang-tools-extra/test/clang-tidy/bugprone-suspicious-semicolon-constexpr.cpp =================================================================== --- /dev/null +++ clang-tools-extra/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 X> +int foo(int a) { + if constexpr(X > 0) { + return a; + } + return a + 1; +} + +int main(void) { + return foo<0>(1); +} Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp @@ -20,7 +20,8 @@ void SuspiciousSemicolonCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( stmt(anyOf(ifStmt(hasThen(nullStmt().bind("semi")), - unless(hasElse(stmt()))), + unless(hasElse(stmt())), + unless(isConstexpr())), forStmt(hasBody(nullStmt().bind("semi"))), cxxForRangeStmt(hasBody(nullStmt().bind("semi"))), whileStmt(hasBody(nullStmt().bind("semi")))))
Index: clang-tools-extra/test/clang-tidy/bugprone-suspicious-semicolon-constexpr.cpp =================================================================== --- /dev/null +++ clang-tools-extra/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 X> +int foo(int a) { + if constexpr(X > 0) { + return a; + } + return a + 1; +} + +int main(void) { + return foo<0>(1); +} Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp @@ -20,7 +20,8 @@ void SuspiciousSemicolonCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( stmt(anyOf(ifStmt(hasThen(nullStmt().bind("semi")), - unless(hasElse(stmt()))), + unless(hasElse(stmt())), + unless(isConstexpr())), forStmt(hasBody(nullStmt().bind("semi"))), cxxForRangeStmt(hasBody(nullStmt().bind("semi"))), whileStmt(hasBody(nullStmt().bind("semi")))))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits