[PATCH] D45932: [clang-tidy][modernize-raw-string-literal] Don't replace upper ASCII with raw literals
Zinovy Nis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 22 13:37:00 PDT 2018
zinovy.nis created this revision.
zinovy.nis added reviewers: xazax.hun, LegalizeAdulthood.
zinovy.nis added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, rnkovacs.
It's useless and not safe to replace
`"\xE2\x98\x83"` with `"☃"` (snowman)
Especially there's an explicit test for ASCII in this check.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D45932
Files:
clang-tidy/modernize/RawStringLiteralCheck.cpp
test/clang-tidy/modernize-raw-string-literal.cpp
Index: test/clang-tidy/modernize-raw-string-literal.cpp
===================================================================
--- test/clang-tidy/modernize-raw-string-literal.cpp
+++ test/clang-tidy/modernize-raw-string-literal.cpp
@@ -40,6 +40,8 @@
char const *const Us("goink\\\037");
char const *const HexNonPrintable("\\\x03");
char const *const Delete("\\\177");
+char const *const MultibyteSnowman("\xE2\x98\x83");
+// CHECK-FIXES: {{^}}char const *const MultibyteSnowman("\xE2\x98\x83");{{$}}
char const *const TrailingSpace("A line \\with space. \n");
char const *const TrailingNewLine("A single \\line.\n");
Index: clang-tidy/modernize/RawStringLiteralCheck.cpp
===================================================================
--- clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -65,6 +65,13 @@
33)) != StringRef::npos)
return false;
+ // Don't replace chars from upper ASCII (>0x7F) as they can represent UTF-8
+ // or be supported by specific code pages only.
+ if (Bytes.find_if([](char C) {
+ return static_cast<unsigned char>(C) > 0x7Fu;
+ }) != StringRef::npos)
+ return false;
+
CharSourceRange CharRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(Literal->getSourceRange()),
*Result.SourceManager, Result.Context->getLangOpts());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45932.143484.patch
Type: text/x-patch
Size: 1403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180422/6c2a0d66/attachment.bin>
More information about the cfe-commits
mailing list