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/Parse/ParseStmt.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/Parse/ParseStmt.cpp')
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 12444e87bb..e3c15680c2 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -538,7 +538,8 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) { bool Parser::ParseParenExprOrCondition(ExprResult &ExprResult, Decl *&DeclResult, SourceLocation Loc, - bool ConvertToBoolean) { + bool ConvertToBoolean, + bool *MacroExpandedAfterRParen) { bool ParseError = false; SourceLocation LParenLoc = ConsumeParen(); @@ -567,7 +568,14 @@ bool Parser::ParseParenExprOrCondition(ExprResult &ExprResult, } // Otherwise the condition is valid or the rparen is present. + + // Catch a macro expansion after ')'. This is used to know that there is a + // macro for 'if' body and not warn for empty body if the macro is empty. + PPMacroExpansionTrap MacroExpansionTrap(PP); MatchRHSPunctuation(tok::r_paren, LParenLoc); + if (MacroExpandedAfterRParen) + *MacroExpandedAfterRParen = MacroExpansionTrap.hasMacroExpansionOccured(); + return false; } @@ -610,7 +618,9 @@ StmtResult Parser::ParseIfStatement(AttributeList *Attr) { // Parse the condition. ExprResult CondExp; Decl *CondVar = 0; - if (ParseParenExprOrCondition(CondExp, CondVar, IfLoc, true)) + bool MacroExpandedInThenStmt; + if (ParseParenExprOrCondition(CondExp, CondVar, IfLoc, true, + &MacroExpandedInThenStmt)) return StmtError(); FullExprArg FullCondExp(Actions.MakeFullExpr(CondExp.get())); @@ -694,7 +704,7 @@ StmtResult Parser::ParseIfStatement(AttributeList *Attr) { ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc); return Actions.ActOnIfStmt(IfLoc, FullCondExp, CondVar, ThenStmt.get(), - ElseLoc, ElseStmt.get()); + MacroExpandedInThenStmt, ElseLoc, ElseStmt.get()); } /// ParseSwitchStatement |