]> granicus.if.org Git - clang/commitdiff
Only ignore extra tokens after #else if we skip it, otherwise warn. Fixes rdar:/...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 21 May 2011 04:26:04 +0000 (04:26 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 21 May 2011 04:26:04 +0000 (04:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131788 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Preprocessor/if_warning.c

index af3fa6e2add79c39d56acffaadbb2807ad5457a7..66e44bbc6dd0be7e0068c3e977d06130fe54a34f 100644 (file)
@@ -323,7 +323,6 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc,
         // #else directive in a skipping conditional.  If not in some other
         // skipping conditional, and if #else hasn't already been seen, enter it
         // as a non-skipping conditional.
-        DiscardUntilEndOfDirective();  // C99 6.10p4.
         PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel();
 
         // If this is a #else with a #else before it, report the error.
@@ -339,7 +338,10 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc,
         // entered, enter the #else block now.
         if (!CondInfo.WasSkipping && !CondInfo.FoundNonSkip) {
           CondInfo.FoundNonSkip = true;
+          CheckEndOfDirective("else");
           break;
+        } else {
+          DiscardUntilEndOfDirective();  // C99 6.10p4.
         }
       } else if (Sub == "lif") {  // "elif".
         PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel();
index 345ac95eb4ba8765bbffd3042b827e8b30db9b13..641ec3b1b970f7c28f8e812d68753eaa95579bed 100644 (file)
@@ -20,6 +20,10 @@ extern int x;
 #endif
 #endif
 
+// rdar://9475098
+#if 0
+#else 1   // expected-warning {{extra tokens}}
+#endif
 
 // PR6852
 #if 'somesillylongthing'  // expected-warning {{character constant too long for its type}} \