[PATCH] D16535: [clang-tidy] Check to find unintended semicolons that changes the semantics.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 9 05:23:33 PST 2016


hokein added inline comments.

================
Comment at: clang-tidy/misc/SuspiciousSemicolonCheck.cpp:23
@@ +22,3 @@
+  Finder->addMatcher(
+      stmt(anyOf(ifStmt(hasThen(nullStmt().bind("semi"))),
+                 forStmt(hasBody(nullStmt().bind("semi"))),
----------------
Looks like this check doesn't handle the case that  unintended semicolon is in `else` statement.

```
if (condition1) {
} else if (condition2);
  a = 2
```

================
Comment at: test/clang-tidy/misc-suspicious-semicolon.cpp:28
@@ +27,3 @@
+{
+  if(x > 5); nop();
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: potentially unintended semicolon [misc-suspicious-semicolon]
----------------
Can you add the following `if` statement cases in the test?

```
if (condition)
  ;
```

```
if (condition)
  ;
else {
}
```

The behavior of the check is that both two cases are not warned. But I think we should warn the first one since there is no reason to write `if` code for that.


http://reviews.llvm.org/D16535





More information about the cfe-commits mailing list