[clang] 4f09ac7 - Fix off-by-one issue found by post-commit review

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 13 04:48:19 PDT 2024


Author: Aaron Ballman
Date: 2024-06-13T07:48:08-04:00
New Revision: 4f09ac7705b3b24492d521a97571404c2e9a1f8e

URL: https://github.com/llvm/llvm-project/commit/4f09ac7705b3b24492d521a97571404c2e9a1f8e
DIFF: https://github.com/llvm/llvm-project/commit/4f09ac7705b3b24492d521a97571404c2e9a1f8e.diff

LOG: Fix off-by-one issue found by post-commit review

Added: 
    

Modified: 
    clang/lib/Lex/Lexer.cpp
    clang/test/Lexer/cxx2c-raw-strings.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index c7543a48c0b50..e59c7805b3862 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2262,7 +2262,6 @@ bool Lexer::LexRawStringLiteral(Token &Result, const char *CurPtr,
   unsigned PrefixLen = 0;
 
   while (PrefixLen != 16 && isRawStringDelimBody(CurPtr[PrefixLen])) {
-    ++PrefixLen;
     if (!isLexingRawMode() &&
         llvm::is_contained({'$', '@', '`'}, CurPtr[PrefixLen])) {
       const char *Pos = &CurPtr[PrefixLen];
@@ -2271,6 +2270,7 @@ bool Lexer::LexRawStringLiteral(Token &Result, const char *CurPtr,
                     : diag::ext_cxx26_raw_string_literal_character_set)
           << StringRef(Pos, 1);
     }
+    ++PrefixLen;
   }
 
   // If the last character was not a '(', then we didn't lex a valid delimiter.

diff  --git a/clang/test/Lexer/cxx2c-raw-strings.cpp b/clang/test/Lexer/cxx2c-raw-strings.cpp
index a1e971434e244..cf114e57d8bb1 100644
--- a/clang/test/Lexer/cxx2c-raw-strings.cpp
+++ b/clang/test/Lexer/cxx2c-raw-strings.cpp
@@ -21,4 +21,8 @@ int main() {
   (void) R"\()\";
   // expected-error at -1 {{invalid character '\' in raw string delimiter}}
   // expected-error at -2 {{expected expression}}
+
+  (void) R"@(foo)@";
+  // cxx26-warning at -1 {{'@' in a raw string literal delimiter is incompatible with standards before C++2c}}
+  // precxx26-warning at -2 {{'@' in a raw string literal delimiter is a C++2c extension}}
 }


        


More information about the cfe-commits mailing list