From b3198178daf9d33466fc18e009e2c6692fdf29c0 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 16 Sep 2010 00:37:05 +0000 Subject: [PATCH] Do not warn about empty bodies for 'if' statements if the body is expanded from a macro. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114049 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaStmt.cpp | 5 ++++- test/Sema/if-empty-body.c | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 84dfa1a999..c9a6da13fb 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -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(thenStmt)) - Diag(stmt->getSemiLoc(), diag::warn_empty_if_body); + if (!stmt->getLocStart().isMacroID()) + Diag(stmt->getSemiLoc(), diag::warn_empty_if_body); } DiagnoseUnusedExprResult(elseStmt); diff --git a/test/Sema/if-empty-body.c b/test/Sema/if-empty-body.c index af1e62f6b1..b28c1cdce9 100644 --- a/test/Sema/if-empty-body.c +++ b/test/Sema/if-empty-body.c @@ -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 +} + -- 2.40.0