Skip to content

Commit cc23574

Browse files
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 <[email protected]>
1 parent ac45220 commit cc23574

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ def err_raw_delim_too_long : Error<
100100
"raw string delimiter longer than 16 characters"
101101
"; use PREFIX( )PREFIX to delimit raw string">;
102102
def err_invalid_char_raw_delim : Error<
103-
"invalid character '%0' character in raw string delimiter"
103+
"invalid character '%0' in raw string delimiter"
104+
"; use PREFIX( )PREFIX to delimit raw string">;
105+
def err_invalid_newline_raw_delim : Error<
106+
"invalid newline character in raw string delimiter"
104107
"; use PREFIX( )PREFIX to delimit raw string">;
105108
def err_unterminated_raw_string : Error<
106109
"raw string missing terminating delimiter )%0\"">;

clang/lib/Lex/Lexer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,8 @@ bool Lexer::LexRawStringLiteral(Token &Result, const char *CurPtr,
22702270
const char *PrefixEnd = &CurPtr[PrefixLen];
22712271
if (PrefixLen == 16) {
22722272
Diag(PrefixEnd, diag::err_raw_delim_too_long);
2273+
} else if (*PrefixEnd == '\n') {
2274+
Diag(PrefixEnd, diag::err_invalid_newline_raw_delim);
22732275
} else {
22742276
Diag(PrefixEnd, diag::err_invalid_char_raw_delim)
22752277
<< StringRef(PrefixEnd, 1);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -E -fsyntax-only -verify %s
2+
3+
// expected-error@+2{{invalid character ')' in raw string delimiter; use PREFIX( )PREFIX to delimit raw string}}
4+
// expected-error@+1{{expected expression}}
5+
char const *str1 = R")";
6+
7+
// expected-error@+2{{invalid newline character in raw string delimiter; use PREFIX( )PREFIX to delimit raw string}}
8+
// expected-error@+1{{expected expression}}
9+
char const* str2 = R"";

0 commit comments

Comments
 (0)