mirror of
https://github.com/intel/llvm.git
synced 2026-01-31 07:27:33 +08:00
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
This commit is contained in:
@@ -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) != '*';
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user