https://github.com/akshaykumars614 updated https://github.com/llvm/llvm-project/pull/81670
>From c2f716ee5f787ec3df63511fd5f565a3deee4d6e Mon Sep 17 00:00:00 2001 From: akshaykumars614 <akshaykumars...@gmail.com> Date: Tue, 13 Feb 2024 16:29:51 -0500 Subject: [PATCH 1/2] issue: #18079 (bad errwqor message on incorrect string literal) Fixed the error message for incorrect string literal --- clang/include/clang/Basic/DiagnosticLexKinds.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 75ca2fa16d3485..c5a2096d02b39d 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -100,7 +100,7 @@ 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 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\"">; >From ac8b99309b07b6c7114dfbf784a46d2fb5d9dcc4 Mon Sep 17 00:00:00 2001 From: akshaykumars614 <akshaykumars...@gmail.com> Date: Wed, 14 Feb 2024 14:04:52 -0500 Subject: [PATCH 2/2] bad error message on incorrect string literal #18079 Introduced new error code for \n delimiter in raw string delimiter. Added testcase to test the same. --- clang/include/clang/Basic/DiagnosticLexKinds.td | 3 +++ clang/lib/Lex/Lexer.cpp | 6 ++++-- clang/test/Lexer/raw-string-dlim-newline.cpp | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 clang/test/Lexer/raw-string-dlim-newline.cpp diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index c5a2096d02b39d..0bc684a9db5793 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -102,6 +102,9 @@ def err_raw_delim_too_long : Error< def err_invalid_char_raw_delim : Error< "invalid newline character in raw string delimiter" "; use PREFIX( )PREFIX to delimit raw string">; +def err_invalid_nexline_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\"">; def warn_cxx98_compat_raw_string_literal : Warning< diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index d927f28b47c270..95f39df7a4628a 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -2270,10 +2270,12 @@ 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 { + } else if (*PrefixEnd != '\n') { Diag(PrefixEnd, diag::err_invalid_char_raw_delim) << StringRef(PrefixEnd, 1); - } + } else { + Diag(PrefixEnd, diag::err_invalid_nexline_raw_delim); + } } // Search for the next '"' in hopes of salvaging the lexer. Unfortunately, diff --git a/clang/test/Lexer/raw-string-dlim-newline.cpp b/clang/test/Lexer/raw-string-dlim-newline.cpp new file mode 100644 index 00000000000000..36939ed864ecae --- /dev/null +++ b/clang/test/Lexer/raw-string-dlim-newline.cpp @@ -0,0 +1,5 @@ +// RUN: not %clang_cc1 -E %s 2>&1 | grep 'error: invalid newline character in raw string delimiter; use PREFIX( )PREFIX to delimit raw string' + +// Introduced new error code err_invalid_nexline_raw_delim for code which has \n as delimiter. +char const* str1 = R" +"; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits