diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-19 20:54:25 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-19 20:54:25 +0000 |
commit | a25b6a4b43e8b9611f7506e5fe1b448833b10a46 (patch) | |
tree | 1c8c6e68f978b9b156704e77c31beb8bf573b845 /lib/Sema/SemaStmt.cpp | |
parent | b95cfe4bb01f18a112bcb7eea3b82bc8d6dfe20b (diff) |
Don't warn for empty 'if' body if there is a macro that expands to nothing, e.g:
if (condition)
CALL(0); // empty macro but don't warn for empty body.
Fixes rdar://8436021.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119838 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index a4f1d34aec..c6194edac3 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -282,8 +282,8 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, StmtResult Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, - Stmt *thenStmt, SourceLocation ElseLoc, - Stmt *elseStmt) { + Stmt *thenStmt, bool MacroExpandedInThenStmt, + SourceLocation ElseLoc, Stmt *elseStmt) { ExprResult CondResult(CondVal.release()); VarDecl *ConditionVar = 0; @@ -304,17 +304,23 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, // 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)) - if (!stmt->getLocStart().isMacroID()) + // But do not warn if the body is a macro that expands to nothing, e.g: + // + // #define CALL(x) + // if (condition) + // CALL(0); + // + if (!MacroExpandedInThenStmt) Diag(stmt->getSemiLoc(), diag::warn_empty_if_body); } DiagnoseUnusedExprResult(elseStmt); return Owned(new (Context) IfStmt(Context, IfLoc, ConditionVar, ConditionExpr, - thenStmt, ElseLoc, elseStmt)); + thenStmt, ElseLoc, elseStmt, + MacroExpandedInThenStmt)); } /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |