<div dir="ltr">This is kicking up false positives on code that does the following:<div><br></div><div>#define USED(x) if(x);else<br></div><div>// ...</div><div>assert(x);</div><div>USED(x);</div><div><br></div><div>It's a bit of a weird pattern, but it occurs in some open-source code and seems easy enough for us to detect (if the semicolon and the preceding token aren't from the same FileID, we shouldn't be diagnosing, because they aren't actually adjacent).</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 16 November 2017 at 13:26, Reid Kleckner via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Thu Nov 16 13:26:18 2017<br>
New Revision: 318456<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=318456&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=318456&view=rev</a><br>
Log:<br>
Issue -Wempty-body warnings for else blocks<br>
<br>
This looks like it was just an oversight.<br>
<br>
Fixes <a href="http://llvm.org/pr35319" rel="noreferrer" target="_blank">http://llvm.org/pr35319</a><br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
    cfe/trunk/lib/Sema/SemaStmt.<wbr>cpp<br>
    cfe/trunk/test/SemaCXX/warn-<wbr>empty-body.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=318456&r1=318455&r2=318456&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/<wbr>DiagnosticSemaKinds.td?rev=<wbr>318456&r1=318455&r2=318456&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td Thu Nov 16 13:26:18 2017<br>
@@ -8090,6 +8090,8 @@ def err_switch_incomplete_class_<wbr>type : E<br>
<br>
 def warn_empty_if_body : Warning<<br>
   "if statement has empty body">, InGroup<EmptyBody>;<br>
+def warn_empty_else_body : Warning<<br>
+  "else clause has empty body">, InGroup<EmptyBody>;<br>
 def warn_empty_for_body : Warning<<br>
   "for loop has empty body">, InGroup<EmptyBody>;<br>
 def warn_empty_range_based_for_<wbr>body : Warning<<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaStmt.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=318456&r1=318455&r2=318456&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaStmt.cpp?rev=318456&r1=<wbr>318455&r2=318456&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaStmt.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaStmt.<wbr>cpp Thu Nov 16 13:26:18 2017<br>
@@ -527,7 +527,9 @@ Sema::ActOnIfStmt(<wbr>SourceLocation IfLoc,<br>
                        CondExpr->getExprLoc()))<br>
     CommaVisitor(*this).Visit(<wbr>CondExpr);<br>
<br>
-  if (!elseStmt)<br>
+  if (elseStmt)<br>
+    DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body);<br>
+  else<br>
     DiagnoseEmptyStmtBody(<wbr>CondExpr->getLocEnd(), thenStmt,<br>
                           diag::warn_empty_if_body);<br>
<br>
<br>
Modified: cfe/trunk/test/SemaCXX/warn-<wbr>empty-body.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-empty-body.cpp?rev=318456&r1=318455&r2=318456&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>SemaCXX/warn-empty-body.cpp?<wbr>rev=318456&r1=318455&r2=<wbr>318456&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaCXX/warn-<wbr>empty-body.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/warn-<wbr>empty-body.cpp Thu Nov 16 13:26:18 2017<br>
@@ -238,6 +238,26 @@ void test6(int x, int y) {<br>
   }<br>
 }<br>
<br>
+void test_if_else(int x) {<br>
+  if (x); // expected-warning{{if statement has empty body}} expected-note{{separate line}}<br>
+<br>
+  if (x)<br>
+    ; // no-warning<br>
+<br>
+  if (x)<br>
+    ; // no-warning<br>
+  else<br>
+    ; // no-warning<br>
+<br>
+  if (x)<br>
+    ; // no-warning<br>
+  else; // expected-warning{{else clause has empty body}} expected-note{{separate line}}<br>
+<br>
+  if (x)<br>
+    ; // no-warning<br>
+  else EMPTY(x); // no-warning<br>
+}<br>
+<br>
 void test_errors(int x) {<br>
   if (1)<br>
     aa; // expected-error{{use of undeclared identifier}}<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>