If we see an invalid #ifdef directive, enter a conditional compilation region

so that we don't emit an error on the #endif.  Suggestion by Neil.

llvm-svn: 42258
This commit is contained in:
Chris Lattner 2007-09-24 05:14:57 +00:00
parent 7d98b23f1a
commit d05e44e74e
2 changed files with 13 additions and 1 deletions

View File

@ -2121,8 +2121,13 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef,
ReadMacroName(MacroNameTok);
// Error reading macro name? If so, diagnostic already issued.
if (MacroNameTok.getKind() == tok::eom)
if (MacroNameTok.getKind() == tok::eom) {
// Skip code until we get to #endif. This helps with recovery by not
// emitting an error when the #endif is reached.
SkipExcludedConditionalBlock(DirectiveTok.getLocation(),
/*Foundnonskip*/false, /*FoundElse*/false);
return;
}
// Check to see if this is the last token on the #if[n]def line.
CheckEndOfDirective(isIfndef ? "#ifndef" : "#ifdef");

View File

@ -0,0 +1,7 @@
/* RUN: clang %s 2>&1 | grep error: | count 1
*/
#ifdef
#endif