Index: clang-tidy/modernize/RawStringLiteralCheck.h =================================================================== --- clang-tidy/modernize/RawStringLiteralCheck.h +++ clang-tidy/modernize/RawStringLiteralCheck.h @@ -32,7 +32,7 @@ private: void replaceWithRawStringLiteral( const ast_matchers::MatchFinder::MatchResult &Result, - const StringLiteral *Literal); + const StringLiteral *Literal, StringRef Replacement); std::string DelimiterStem; }; Index: clang-tidy/modernize/RawStringLiteralCheck.cpp =================================================================== --- clang-tidy/modernize/RawStringLiteralCheck.cpp +++ clang-tidy/modernize/RawStringLiteralCheck.cpp @@ -121,19 +121,24 @@ if (Literal->getLocStart().isMacroID()) return; - if (containsEscapedCharacters(Result, Literal)) - replaceWithRawStringLiteral(Result, Literal); + if (containsEscapedCharacters(Result, Literal)) { + std::string Replacement = asRawStringLiteral(Literal, DelimiterStem); + if (Replacement.length() <= + Lexer::MeasureTokenLength(Literal->getLocStart(), *Result.SourceManager, + getLangOpts())) + replaceWithRawStringLiteral(Result, Literal, Replacement); + } } void RawStringLiteralCheck::replaceWithRawStringLiteral( - const MatchFinder::MatchResult &Result, const StringLiteral *Literal) { + const MatchFinder::MatchResult &Result, const StringLiteral *Literal, + StringRef Replacement) { CharSourceRange CharRange = Lexer::makeFileCharRange( CharSourceRange::getTokenRange(Literal->getSourceRange()), *Result.SourceManager, getLangOpts()); diag(Literal->getLocStart(), "escaped string literal can be written as a raw string literal") - << FixItHint::CreateReplacement( - CharRange, asRawStringLiteral(Literal, DelimiterStem)); + << FixItHint::CreateReplacement(CharRange, Replacement); } } // namespace modernize 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 @@ -91,6 +91,11 @@ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal // CHECK-FIXES: {{^}}char const *const HexPrintable(R"(@\)");{{$}} +char const *const Concatenated("\"foo\"" + "\"bar\""); +// CHECK-MESSAGES: :[[@LINE-2]]:32: warning: {{.*}} can be written as a raw string literal +// CHECK-FIXES: {{^}}char const *const Concatenated(R"("foo""bar")");{{$}} + char const *const prettyFunction(__PRETTY_FUNCTION__); char const *const function(__FUNCTION__); char const *const func(__func__);