diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-17 23:30:53 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-17 23:30:53 +0000 |
commit | 0003c27f5e7d19b4069a098a33b14674c39dccb2 (patch) | |
tree | d0dfadde5567cad1fa70b19611d294e3c026534e /clang/lib | |
parent | 06684350c4428df2d18fce93e8b68379da9798dc (diff) | |
download | bcm5719-llvm-0003c27f5e7d19b4069a098a33b14674c39dccb2.tar.gz bcm5719-llvm-0003c27f5e7d19b4069a098a33b14674c39dccb2.zip |
#line is allowed to have macros that expand to nothing after them.
llvm-svn: 69401
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 742076956d2..ce86d0edca0 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -101,12 +101,17 @@ void Preprocessor::ReadMacroName(Token &MacroNameTok, char isDefineUndef) { } /// CheckEndOfDirective - Ensure that the next token is a tok::eom token. If -/// not, emit a diagnostic and consume up until the eom. -void Preprocessor::CheckEndOfDirective(const char *DirType) { +/// not, emit a diagnostic and consume up until the eom. If EnableMacros is +/// true, then we consider macros that expand to zero tokens as being ok. +void Preprocessor::CheckEndOfDirective(const char *DirType, bool EnableMacros) { Token Tmp; - // Lex unexpanded tokens: macros might expand to zero tokens, causing us to - // miss diagnosing invalid lines. - LexUnexpandedToken(Tmp); + // Lex unexpanded tokens for most directives: macros might expand to zero + // tokens, causing us to miss diagnosing invalid lines. Some directives (like + // #line) allow empty macros. + if (EnableMacros) + Lex(Tmp); + else + LexUnexpandedToken(Tmp); // There should be no tokens after the directive, but we allow them as an // extension. @@ -694,8 +699,9 @@ void Preprocessor::HandleLineDirective(Token &Tok) { FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString(), Literal.GetStringLength()); - // Verify that there is nothing after the string, other than EOM. - CheckEndOfDirective("line"); + // Verify that there is nothing after the string, other than EOM. Because + // of C99 6.10.4p5, macros that expand to empty tokens are ok. + CheckEndOfDirective("line", true); } SourceMgr.AddLineNote(DigitTok.getLocation(), LineNo, FilenameID); |