@@ -419,7 +419,6 @@ static bool isQuoteCppDigitSeparator(const char *const Start,
419419}
420420
421421void Scanner::skipLine (const char *&First, const char *const End) {
422- const char *const OldFirst = First;
423422 for (;;) {
424423 assert (First <= End);
425424 if (First == End)
@@ -430,6 +429,9 @@ void Scanner::skipLine(const char *&First, const char *const End) {
430429 return ;
431430 }
432431 const char *Start = First;
432+ // Use `LastNonWhitespace`to track if a line-continuation has ever been seen
433+ // before a new-line character:
434+ char LastNonWhitespace = ' ' ;
433435 while (First != End && !isVerticalWhitespace (*First)) {
434436 // Iterate over strings correctly to avoid comments and newlines.
435437 if (*First == ' "' ||
@@ -453,6 +455,8 @@ void Scanner::skipLine(const char *&First, const char *const End) {
453455 // Iterate over comments correctly.
454456 if (*First != ' /' || End - First < 2 ) {
455457 LastTokenPtr = First;
458+ if (!isWhitespace (*First))
459+ LastNonWhitespace = *First;
456460 ++First;
457461 continue ;
458462 }
@@ -465,6 +469,8 @@ void Scanner::skipLine(const char *&First, const char *const End) {
465469
466470 if (First[1 ] != ' *' ) {
467471 LastTokenPtr = First;
472+ if (!isWhitespace (*First))
473+ LastNonWhitespace = *First;
468474 ++First;
469475 continue ;
470476 }
@@ -476,26 +482,9 @@ void Scanner::skipLine(const char *&First, const char *const End) {
476482 return ;
477483
478484 // Skip over the newline.
479- auto Len = skipNewline (First, End);
480- // Since P2223R2 allows the line-continuation slash \ to be followed by
481- // additional whitespace, we need to check that here if `First`
482- // follows a `\\` and whitespaces.
483-
484- // `LookBack` points to the character before the newline:
485- const char *LookBack = First - Len;
486- bool LineContinuationFound = false ;
487-
488- // Move `LookBack` backwards to find line-continuation and whitespaces:
489- while (LookBack >= OldFirst) { // bound `LookBack` by `OldFirst`:
490- if (isWhitespace (*LookBack)) {
491- --LookBack; // whitespace before '\\' is ok
492- continue ;
493- }
494- if (*LookBack == ' \\ ' )
495- LineContinuationFound = true ;
496- break ; // not a whitespace, end loop
497- }
498- if (!LineContinuationFound)
485+ skipNewline (First, End);
486+
487+ if (LastNonWhitespace != ' \\ ' )
499488 break ;
500489 }
501490}
0 commit comments