Commit 5c5e8605 authored by Gabor Horvath's avatar Gabor Horvath
Browse files

[clang-tidy] Fix PR35824

Differential Revision: https://reviews.llvm.org/D46027
parent b98a0c7f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ namespace bugprone {
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")))))
+31 −0
Original line number Diff line number Diff line
// 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;
}

template <int X>
int foo2(int a) {
    // FIXME: diagnose the case below. See https://reviews.llvm.org/D46234
    // for details.
    if constexpr(X > 0);
        return a;
    return a + 1;
}

int main(void) {
    foo2<0>(1);
    return foo<0>(1);
}