diff options
Diffstat (limited to 'clang/lib/Parse/ParseStmt.cpp')
-rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 12444e87bbd..e3c15680c23 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/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 |