Skip to content

Commit

Permalink
bad error message on incorrect string literal #18079 (#81670)
Browse files Browse the repository at this point in the history
(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@gmail.com>
  • Loading branch information
akshaykumars614 and jroelofs committed Feb 16, 2024
1 parent ac45220 commit cc23574
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clang/include/clang/Basic/DiagnosticLexKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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\"">;
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Lex/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Lexer/raw-string-dlim-invalid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang_cc1 -E -fsyntax-only -verify %s

// expected-error@+2{{invalid character ')' in raw string delimiter; use PREFIX( )PREFIX to delimit raw string}}
// expected-error@+1{{expected expression}}
char const *str1 = R")";

// expected-error@+2{{invalid newline character in raw string delimiter; use PREFIX( )PREFIX to delimit raw string}}
// expected-error@+1{{expected expression}}
char const* str2 = R"";

0 comments on commit cc23574

Please sign in to comment.