]> granicus.if.org Git - clang/commitdiff
Preproceessor: fix #if skipping under -traditional-cpp.
authorJordan Rose <jordan_rose@apple.com>
Fri, 22 Feb 2013 00:32:00 +0000 (00:32 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 22 Feb 2013 00:32:00 +0000 (00:32 +0000)
When parsing directives within skipped #if blocks, we don't want to retain
any whitespace. Previously we were just skipping comments, but it's not
possible to skip comments and retain other whitespace. This change matches
the usual behavior for parsing directives (i.e. the behavior outside of
skipped #if blocks).

<rdar://problem/13267695>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175840 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Preprocessor/traditional-cpp.c

index 54457c36cfde0a303214ccf1a8450780df66a88b..10446832124337ffb4cd9ac0258b2bf0a4f86f96 100644 (file)
@@ -258,7 +258,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc,
     // directive mode.  Tell the lexer this so any newlines we see will be
     // converted into an EOD token (this terminates the macro).
     CurPPLexer->ParsingPreprocessorDirective = true;
-    if (CurLexer) CurLexer->SetCommentRetentionState(false);
+    if (CurLexer) CurLexer->SetKeepWhitespaceMode(false);
 
 
     // Read the next token, the directive flavor.
index 72024546ff3d6af83a54260d5280322946783ebb..5a94c00c969fb969ed611f580e905c3bcbc3e72a 100644 (file)
@@ -62,3 +62,19 @@ bracket2(spaces)
 /* If this were working, this check would be on.
  * CHECK-NOT: {{^}}>>>  spaces  <<<{{$}}
  */
+
+
+/* Check that #if 0 blocks work as expected */
+#if 0
+#error "this is not an error"
+
+#if 1
+a b c in skipped block
+#endif
+
+/* Comments are whitespace too */
+
+#endif
+/* CHECK-NOT: {{^}}a b c in skipped block{{$}}
+ * CHECK-NOT: {{^}}/* Comments are whitespace too
+ */