[PATCH] D16529: [clang-tidy] Add modernize-raw-string-literal check

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 25 07:47:20 PST 2016

aaron.ballman added a subscriber: aaron.ballman.

Comment at: clang-tidy/modernize/RawStringLiteralCheck.cpp:35
@@ +34,3 @@
+  const bool HasBackSlash = Text.find(R"(\\)") != StringRef::npos;
+  const bool HasNewLine = Text.find(R"(\n)") != StringRef::npos;
+  const bool HasQuote = Text.find(R"(\')") != StringRef::npos;
Newlines are hard. Should this also handle \r (for CRLF code like \r\n)?

Comment at: clang-tidy/modernize/RawStringLiteralCheck.cpp:66
@@ +65,3 @@
+void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(stringLiteral().bind("lit"), this);
Please limit registration of the checker to just C++11 or later.

Comment at: test/clang-tidy/modernize-raw-string-literal.cpp:18
@@ +17,3 @@
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} can be written as a raw string literal
+// CHECK-FIXES: {{^}}char const *const NewLine{R"(goink{{$}}
+// CHECK-FIXES-NEXT: {{^}}frob)"};{{$}}
Is there a way that this fix-it can mangle the source file in scary ways, though? For instance, say I have a source file saved with CRLF and a string literal of "foo\nbar" -- this will either make the string literal contain a CRLF instead of just LF, or it will make the string literal contain an LF right up until the user's editor saves the file and converts the line ending (I think).

Comment at: test/clang-tidy/modernize-raw-string-literal.cpp:55
@@ +54,2 @@
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal
+// CHECK-FIXES: {{^}}char const *const HexPrintable{R"(@\)"};{{$}}
Can you also add a test that ensures we don't mangle already-raw string literals (by re-rawifying them)?


More information about the cfe-commits mailing list