[clang] cc23574 - bad error message on incorrect string literal #18079 (#81670)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 15 17:07:57 PST 2024
Author: akshaykumars614
Date: 2024-02-15T20:07:54-05:00
New Revision: cc23574184335df187275ca0e716bf79b93b75f1
URL: https://github.com/llvm/llvm-project/commit/cc23574184335df187275ca0e716bf79b93b75f1
DIFF: https://github.com/llvm/llvm-project/commit/cc23574184335df187275ca0e716bf79b93b75f1.diff
LOG: bad error message on incorrect string literal #18079 (#81670)
(bad error message on incorrect string literal)
Fixed the error message for incorrect string literal
before:
```
test.cpp:1:19: error: invalid character '
' character in raw string delimiter; use PREFIX( )PREFIX to delimit raw string
char const* a = R"
^
```
now:
```
test.cpp:1:19: error: invalid newline character in raw string delimiter; use PREFIX( )PREFIX to delimit raw string
1 | char const* a = R"
| ^
```
---------
Co-authored-by: Jon Roelofs <jroelofs at gmail.com>
Added:
clang/test/Lexer/raw-string-dlim-invalid.cpp
Modified:
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 1354543612b9fb..d7c172e6546351 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -100,7 +100,10 @@ def err_raw_delim_too_long : Error<
"raw string delimiter longer than 16 characters"
"; use PREFIX( )PREFIX to delimit raw string">;
def err_invalid_char_raw_delim : Error<
- "invalid character '%0' character in raw string delimiter"
+ "invalid character '%0' in raw string delimiter"
+ "; use PREFIX( )PREFIX to delimit raw string">;
+def err_invalid_newline_raw_delim : Error<
+ "invalid newline character in raw string delimiter"
"; use PREFIX( )PREFIX to delimit raw string">;
def err_unterminated_raw_string : Error<
"raw string missing terminating delimiter )%0\"">;
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index d927f28b47c270..c98645993abe07 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2270,6 +2270,8 @@ bool Lexer::LexRawStringLiteral(Token &Result, const char *CurPtr,
const char *PrefixEnd = &CurPtr[PrefixLen];
if (PrefixLen == 16) {
Diag(PrefixEnd, diag::err_raw_delim_too_long);
+ } else if (*PrefixEnd == '\n') {
+ Diag(PrefixEnd, diag::err_invalid_newline_raw_delim);
} else {
Diag(PrefixEnd, diag::err_invalid_char_raw_delim)
<< StringRef(PrefixEnd, 1);
diff --git a/clang/test/Lexer/raw-string-dlim-invalid.cpp b/clang/test/Lexer/raw-string-dlim-invalid.cpp
new file mode 100644
index 00000000000000..da797f00a1d628
--- /dev/null
+++ b/clang/test/Lexer/raw-string-dlim-invalid.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -E -fsyntax-only -verify %s
+
+// expected-error at +2{{invalid character ')' in raw string delimiter; use PREFIX( )PREFIX to delimit raw string}}
+// expected-error at +1{{expected expression}}
+char const *str1 = R")";
+
+// expected-error at +2{{invalid newline character in raw string delimiter; use PREFIX( )PREFIX to delimit raw string}}
+// expected-error at +1{{expected expression}}
+char const* str2 = R"";
More information about the cfe-commits
mailing list