From 176057b5781e955fcfd908e90b20528292b50004 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Fri, 22 Feb 2013 00:32:00 +0000 Subject: [PATCH] Preproceessor: fix #if skipping under -traditional-cpp. 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). llvm-svn: 175840 --- clang/lib/Lex/PPDirectives.cpp | 2 +- clang/test/Preprocessor/traditional-cpp.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 54457c3..1044683 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -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. diff --git a/clang/test/Preprocessor/traditional-cpp.c b/clang/test/Preprocessor/traditional-cpp.c index 7202454..5a94c00 100644 --- a/clang/test/Preprocessor/traditional-cpp.c +++ b/clang/test/Preprocessor/traditional-cpp.c @@ -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 + */ -- 2.7.4