-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang-tidy] Detect string literals in macros in modernize-raw-string… #133636
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,6 +181,10 @@ Changes in existing checks | |
| <clang-tidy/checks/modernize/use-std-numbers>` check to support math | ||
| functions of different precisions. | ||
|
|
||
| - Improved :doc:`modernize-raw-string-literal | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep alphabetical order (by check name) in this list. |
||
| <clang-tidy/checks/modernize/raw-string-literal>` check to detect string | ||
| literals passed into macros. | ||
|
|
||
| - Improved :doc:`performance-move-const-arg | ||
| <clang-tidy/checks/performance/move-const-arg>` check by fixing false | ||
| negatives on ternary operators calling ``std::move``. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,7 +105,8 @@ char const *const StringizedMacroArgument = HAT(foo\\bar); | |
|
|
||
| #define SUBST(lit_) lit_ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about concat string in macro?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, this doesn't work. It wants to create a replacement Most likely macros should be handled in a |
||
| char const *const MacroArgument = SUBST("foo\\bar"); | ||
| // FIXME: We should be able to replace this string literal macro argument | ||
| // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: {{.*}} can be written as a raw string literal | ||
| // CHECK-FIXES: {{^}}char const *const MacroArgument = SUBST(R"(foo\bar)");{{$}} | ||
|
|
||
| template <typename T> | ||
| void fn(char const *const Arg) { | ||
|
|
||
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.
Why is this necessary?
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.
It picked up on this:
Since
foo\\bardoes not have quotes, the assertion insideisRawStringLiteralfailed.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.
So... shouldn't the check include something that says this is only when the text is a macro argument to
#, or am I missing something?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.
I'm not sure I understand the question. Do you mean that we should update the user-facing documentation of the check? Or that we should modify the implementation?
Uh oh!
There was an error while loading. Please reload this page.
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.
I mean this is a blanket-wide check to see if the text contains a double quote character (
"), but isn't contextualized to the specific case that matters -- when the text is supplied as a macro argument to the preprocessor string-ize operator#. I don't see how adding this condition applies only to that situation.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.
Yeah, that won't work. Do note this PR is abandoned :)
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.
Yes, I just wanted to understand the change as written to make sure I wasn't missing something
:). FYI, I am the one who contributed this check and a weakness of several early checks I wrote is that they don't play well with macros and this was one of them.