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

via cfe-commits cfe-commits at lists.llvm.org
Thu May 30 12:47:20 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

<details>
<summary>Changes</summary>

Fix regression introduced by #<!-- -->93216

---
Full diff: https://github.com/llvm/llvm-project/pull/93867.diff


2 Files Affected:

- (modified) clang/include/clang/Basic/CharInfo.h (+1-1) 
- (modified) clang/test/Lexer/cxx2c-raw-strings.cpp (+17-5) 


``````````diff
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}}
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/93867


More information about the cfe-commits mailing list