]> granicus.if.org Git - clang/commitdiff
Do not warn about empty bodies for 'if' statements if the body is expanded from a...
authorTed Kremenek <kremenek@apple.com>
Thu, 16 Sep 2010 00:37:05 +0000 (00:37 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 16 Sep 2010 00:37:05 +0000 (00:37 +0000)
Fixes <rdar://problem/8436021>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114049 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmt.cpp
test/Sema/if-empty-body.c

index 84dfa1a9999d2ef814caf7d5dc8522c35e415832..c9a6da13fbe1551ff2051b4b162d3dc251503ae5 100644 (file)
@@ -272,9 +272,12 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar,
   // this helps prevent bugs due to typos, such as
   // if (condition);
   //   do_stuff();
+  //
+  // NOTE: Do not emit this warning if the body is expanded from a macro.
   if (!elseStmt) {
     if (NullStmt* stmt = dyn_cast<NullStmt>(thenStmt))
-      Diag(stmt->getSemiLoc(), diag::warn_empty_if_body);
+      if (!stmt->getLocStart().isMacroID())
+        Diag(stmt->getSemiLoc(), diag::warn_empty_if_body);
   }
 
   DiagnoseUnusedExprResult(elseStmt);
index af1e62f6b1b61c2696c207e71aa92f8378f75de8..b28c1cdce962f4cb97f5e4d9f73ad6a351951ac8 100644 (file)
@@ -14,3 +14,11 @@ void f3() {
   return;    // no empty body warning.
 }
 
+// Don't warn about an empty body if is expanded from a macro.
+void f4(int i) {
+  #define BODY ;
+  if (i == i) // expected-warning{{self-comparison always evaluates to true}}
+    BODY
+  #undef BODY
+}
+