-
Notifications
You must be signed in to change notification settings - Fork 13.5k
bad error message on incorrect string literal #18079 #81670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
(bad errwqor message on incorrect string literal) Fixed the error message for incorrect string literal
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: None (akshaykumars614) Changes(bad error message on incorrect string literal) Fixed the error message for incorrect string literal before: test.cpp:1:19: error: invalid character ' now: test.cpp:1:19: error: invalid newline character in raw string delimiter; use PREFIX( )PREFIX to delimit raw string Full diff: https://github.com/llvm/llvm-project/pull/81670.diff 1 Files Affected:
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\"">;
|
I am new to this project. Please let me know if any files need to be added. I don't believe any testing or test suite changes are required for this change. |
This particular change will break this usage of that diagnostic, which expects that format argument: llvm-project/clang/lib/Lex/Lexer.cpp Lines 2274 to 2275 in e06f352
The change needs to account for cases where the character should still be printed, and when it isn't printable or would have strange formatting. And then it should be accompanied by a test that verifies the new behavior. |
Got it. Thank you for helping me. I will look upon it further. Now should I close this pull request or add the updated commit here itself? |
Feel free to keep it open and push more commits to the branch. |
Introduced new error code for \n delimiter in raw string delimiter. Added testcase to test the same.
✅ With the latest revision this PR passed the C/C++ code formatter. |
Co-authored-by: Jon Roelofs <[email protected]>
Co-authored-by: Jon Roelofs <[email protected]>
Co-authored-by: Jon Roelofs <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Let me know if you need me to press the "merge" button for you.
Thank you for reviewing:) |
@akshaykumars614 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Should we be looking for If the testcase is checked out with DOS line endings (e.g. on a windows machine), then the test clang/test/Lexer/raw-string-dlim-invalid.cpp fails I don't know what the C++ spec says, but I think this diagnostic should work for both common end of line styles. Something like this: diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index c98645993abe..e2ab928c04ee 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2270,7 +2270,7 @@ 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') {
+ } else if ((*PrefixEnd == '\r' && PrefixEnd[1] == '\n') || *PrefixEnd == '\n') {
Diag(PrefixEnd, diag::err_invalid_newline_raw_delim);
} else {
Diag(PrefixEnd, diag::err_invalid_char_raw_delim)
? |
It would be better to do, in all cases Diag(PrefixEnd, diag::err_invalid_char_raw_delim) << escapeCStyle<EscapeChar::Single>(*PrefixEnd); (and remove the |
(bad error message on incorrect string literal)
Fixed the error message for incorrect string literal
before:
now: