This check examines string literals and looks for those that could be more directly expressed as a raw string literal.
Example:
char const *const BackSlash{"goink\\frob"};
becomes:
char const *const BackSlash{R"(goink\frob)"};
Addresses PR24444
Differential D16529
[clang-tidy] Add modernize-raw-string-literal check LegalizeAdulthood on Jan 25 2016, 4:02 AM. Authored by
Details
This check examines string literals and looks for those that could be more directly expressed as a raw string literal. Example: char const *const BackSlash{"goink\\frob"}; becomes: char const *const BackSlash{R"(goink\frob)"}; Addresses PR24444
Diff Detail Event Timeline
Comment Actions Update from comments:
Comment Actions Update from review comments. Comment Actions Ugh, I didn't even notice they were in there. It must have errantly slipped in from rebasing. Comment Actions Thank you for addressing (most of) the comments! I have a few more comments and the comment about the implementation of asRawStringLiteral still applies. Also, please remove unrelated files from the patch.
Comment Actions There are still a few comments open. One more important thing is to try running this check over a large enough project (LLVM + Clang, for example), apply fixes, look at the results and try to build the fixed code and run all tests. You can use the clang-tidy/tool/run-clang-tidy.py script (with proper -clang-tidy-binary and -clang-apply-replacements-binary options) to run the check and apply the fixes.
Comment Actions I agree it needs more testing. I think also my current approach to newlines is overly aggressive and will result in more raw string literals than people would prefer. It's really the Windows style path separators and regex ones that are not controversial transformations.
Comment Actions Update from review comments. Added a bunch of test cases for non-printing characters, templates and macros. Removed string literals containing newline (\n) from being considered for transformation to raw string literals. Comment Actions I wrote:
Unfortunately in this paragraph I used the term "literal" in several places where I should have said "delimiter". I hope that wasn't too confusing. It should have read:
Comment Actions Sorry for the delay. I'm trying to prioritize reviews that are taking less time per-iteration. Unfortunately, here we have a bunch of disagreements and I have to spend significant time to read through your arguments and address your points.
Comment Actions Update from review comments. Comment Actions Add FIXME for non-ASCII string literals. Comment Actions Sorry for the delay, I was at WG21 meetings last week, so code reviews mostly were ignored by me. I think this check LGTM, but please wait for @alexfh before committing.
Comment Actions I do not have commit access, so I will need someone to commit this for me. Patch by Richard Thomson thanks.
Comment Actions Looks mostly good, a few nits.
Comment Actions Update from comments. I do not have commit access. Patch by Richard Thomson Comment Actions When running the tests from this patch locally (Win10, MSVC 2015, debug, x64), I get: 1>------ Build started: Project: intrinsics_gen, Configuration: Debug x64 ------ Build: 53 succeeded, 1 failed, 161 up-to-date, 0 skippedComment Actions Looks like I forgot to remove brace initializers from the test files. I will fix that. Chris Lattner has given me commit access now, so I can commit on my own. |
Might make sense to hoist this check out of containsEscapedCharacters since it has nothing to do with escaped chars, really. Regardless, comments should be full sentences with capitalization and punctuation (here and elsewhere in the file).