[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:46:52 PDT 2024
https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/93867
Fix regression introduced by #93216
>From 03737382aaacacc1aecb0c416bc2036b634bdd72 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Thu, 30 May 2024 21:32:34 +0200
Subject: [PATCH] [Clang] \ is not valid in a raw string literal
Fix regression introduced by #93216
---
clang/include/clang/Basic/CharInfo.h | 2 +-
clang/test/Lexer/cxx2c-raw-strings.cpp | 22 +++++++++++++++++-----
2 files changed, 18 insertions(+), 6 deletions(-)
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