diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2013-08-28 20:53:32 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2013-08-28 20:53:32 +0000 |
commit | cefc7eafc6553652d2e7e7d40158af84c86bf38d (patch) | |
tree | d583342316f2ba6741e19e2bee2984373db4fcd1 | |
parent | 1a26c209f61b4b16aa4106185d87951b04518c6d (diff) | |
download | bcm5719-llvm-cefc7eafc6553652d2e7e7d40158af84c86bf38d.tar.gz bcm5719-llvm-cefc7eafc6553652d2e7e7d40158af84c86bf38d.zip |
Fix "//" comments with -traditional-cpp in C++.
Apparently, gcc's -traditional-cpp behaves slightly differently in C++ mode;
specifically, it discards "//" comments. Match gcc's behavior.
<rdar://problem/14808126>
llvm-svn: 189515
-rw-r--r-- | clang/lib/Lex/Lexer.cpp | 6 | ||||
-rw-r--r-- | clang/test/Preprocessor/traditional-cpp.c | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index e3e01da8416..4b6852ba90b 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -2868,7 +2868,8 @@ LexNextToken: // If the next token is obviously a // or /* */ comment, skip it efficiently // too (without going through the big switch stmt). if (CurPtr[0] == '/' && CurPtr[1] == '/' && !inKeepCommentMode() && - LangOpts.LineComment && !LangOpts.TraditionalCPP) { + LangOpts.LineComment && + (LangOpts.CPlusPlus || !LangOpts.TraditionalCPP)) { if (SkipLineComment(Result, CurPtr+2)) return; // There is a token to return. goto SkipIgnoredUnits; @@ -3165,7 +3166,8 @@ LexNextToken: // "foo". Check to see if the character after the second slash is a '*'. // If so, we will lex that as a "/" instead of the start of a comment. // However, we never do this if we are just preprocessing. - bool TreatAsComment = LangOpts.LineComment && !LangOpts.TraditionalCPP; + bool TreatAsComment = LangOpts.LineComment && + (LangOpts.CPlusPlus || !LangOpts.TraditionalCPP); if (!TreatAsComment) if (!(PP && PP->isPreprocessedOutput())) TreatAsComment = getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*'; diff --git a/clang/test/Preprocessor/traditional-cpp.c b/clang/test/Preprocessor/traditional-cpp.c index b8bb99d93cb..aa9f0f146e4 100644 --- a/clang/test/Preprocessor/traditional-cpp.c +++ b/clang/test/Preprocessor/traditional-cpp.c @@ -3,9 +3,9 @@ * things like using /usr/bin/cpp to preprocess non-source files. */ /* - RUN: %clang_cc1 -traditional-cpp %s -E -o %t - RUN: FileCheck -strict-whitespace < %t %s + RUN: %clang_cc1 -traditional-cpp %s -E | FileCheck -strict-whitespace %s RUN: %clang_cc1 -traditional-cpp %s -E -C | FileCheck -check-prefix=CHECK-COMMENTS %s + RUN: %clang_cc1 -traditional-cpp -x c++ %s -E | FileCheck -check-prefix=CHECK-CXX %s */ /* -traditional-cpp should eliminate all C89 comments. */ @@ -13,7 +13,9 @@ * CHECK-COMMENTS: {{^}}/* -traditional-cpp should eliminate all C89 comments. *{{/$}} */ +/* -traditional-cpp should only eliminate "//" comments in C++ mode. */ /* CHECK: {{^}}foo // bar{{$}} + * CHECK-CXX: {{^}}foo {{$}} */ foo // bar |