[clang] 6bc71ba - [Clang] \ is not valid in a raw string literal (#93867)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 4 00:35:38 PDT 2024


Author: cor3ntin
Date: 2024-06-04T09:35:35+02:00
New Revision: 6bc71bac8728b30b560f7ae210917072b01b8046

URL: https://github.com/llvm/llvm-project/commit/6bc71bac8728b30b560f7ae210917072b01b8046
DIFF: https://github.com/llvm/llvm-project/commit/6bc71bac8728b30b560f7ae210917072b01b8046.diff

LOG: [Clang] \ is not valid in a raw string literal (#93867)

Fix regression introduced by #93216

Added: 
    

Modified: 
    clang/include/clang/Basic/CharInfo.h
    clang/test/Lexer/cxx2c-raw-strings.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/CharInfo.h b/clang/include/clang/Basic/CharInfo.h
index d71857e8e5dcc..87626eeb8a700 100644
--- a/clang/include/clang/Basic/CharInfo.h
+++ b/clang/include/clang/Basic/CharInfo.h
@@ -176,7 +176,7 @@ LLVM_READONLY inline bool isRawStringDelimBody(unsigned char c) {
   using namespace charinfo;
   return (InfoTable[c] & (CHAR_UPPER | CHAR_LOWER | CHAR_PERIOD | CHAR_DIGIT |
                           CHAR_UNDER | CHAR_PUNCT)) != 0 &&
-         c != '(' && c != ')';
+         c != '(' && c != ')' && c != '\\';
 }
 
 enum class EscapeChar {

diff  --git a/clang/test/Lexer/cxx2c-raw-strings.cpp b/clang/test/Lexer/cxx2c-raw-strings.cpp
index 569a4b8447e57..a1e971434e244 100644
--- a/clang/test/Lexer/cxx2c-raw-strings.cpp
+++ b/clang/test/Lexer/cxx2c-raw-strings.cpp
@@ -1,12 +1,24 @@
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wc++26-extensions %s
-// RUN: %clang_cc1 -std=c++2c -fsyntax-only -verify=cxx26 -Wpre-c++26-compat %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=precxx26,expected -Wc++26-extensions %s
+// RUN: %clang_cc1 -std=c++2c -fsyntax-only -verify=cxx26,expected -Wpre-c++26-compat %s
 
 int main() {
   (void) R"abc`@$(foobar)abc`@$";
-  //expected-warning at -1 {{'`' in a raw string literal delimiter is a C++2c extension}}
-  //expected-warning at -2 {{'@' in a raw string literal delimiter is a C++2c extension}}
-  //expected-warning at -3 {{'$' in a raw string literal delimiter is a C++2c extension}}
+  //precxx26-warning at -1 {{'`' in a raw string literal delimiter is a C++2c extension}}
+  //precxx26-warning at -2 {{'@' in a raw string literal delimiter is a C++2c extension}}
+  //precxx26-warning at -3 {{'$' in a raw string literal delimiter is a C++2c extension}}
   //cxx26-warning at -4 {{'`' in a raw string literal delimiter is incompatible with standards before C++2c}}
   //cxx26-warning at -5 {{'@' in a raw string literal delimiter is incompatible with standards before C++2c}}
   //cxx26-warning at -6 {{'$' in a raw string literal delimiter is incompatible with standards before C++2c}}
+
+  (void) R"\t()\t";
+  // expected-error at -1 {{invalid character '\' in raw string delimiter}}
+  // expected-error at -2 {{expected expression}}
+
+  (void) R" () ";
+  // expected-error at -1 {{invalid character ' ' in raw string delimiter}}
+  // expected-error at -2 {{expected expression}}
+
+  (void) R"\()\";
+  // expected-error at -1 {{invalid character '\' in raw string delimiter}}
+  // expected-error at -2 {{expected expression}}
 }


        


More information about the cfe-commits mailing list