@@ -58,7 +58,7 @@ bool containsEscapedCharacters(const MatchFinder::MatchResult &Result,
5858 *Result.SourceManager , Result.Context ->getLangOpts ());
5959 StringRef Text = Lexer::getSourceText (CharRange, *Result.SourceManager ,
6060 Result.Context ->getLangOpts ());
61- if (Text.empty () || isRawStringLiteral (Text))
61+ if (Text.empty () || !Text. contains ( ' " ' ) || isRawStringLiteral (Text))
6262 return false ;
6363
6464 return containsEscapes (Text, R"( '\"?x01)" );
@@ -156,14 +156,14 @@ static bool compareStringLength(StringRef Replacement,
156156 const SourceManager &SM,
157157 const LangOptions &LangOpts) {
158158 return Replacement.size () <=
159- Lexer::MeasureTokenLength (Literal->getBeginLoc (), SM, LangOpts);
159+ Lexer::MeasureTokenLength (SM. getSpellingLoc ( Literal->getBeginLoc () ), SM, LangOpts);
160160}
161161
162162void RawStringLiteralCheck::check (const MatchFinder::MatchResult &Result) {
163163 const auto *Literal = Result.Nodes .getNodeAs <StringLiteral>(" lit" );
164- if (Literal->getBeginLoc ().isMacroID ())
165- return ;
166164 const SourceManager &SM = *Result.SourceManager ;
165+ if (SM.getSpellingLoc (Literal->getBeginLoc ()).isMacroID ())
166+ return ;
167167 const LangOptions &LangOpts = getLangOpts ();
168168 if (containsEscapedCharacters (Result, Literal, DisallowedChars)) {
169169 const std::string Replacement =
@@ -172,7 +172,8 @@ void RawStringLiteralCheck::check(const MatchFinder::MatchResult &Result) {
172172 compareStringLength (Replacement, Literal, SM, LangOpts)) {
173173 diag (Literal->getBeginLoc (),
174174 " escaped string literal can be written as a raw string literal" )
175- << FixItHint::CreateReplacement (Literal->getSourceRange (),
175+ << FixItHint::CreateReplacement (SourceRange (SM.getSpellingLoc (Literal->getBeginLoc ()),
176+ SM.getSpellingLoc (Literal->getEndLoc ())),
176177 Replacement);
177178 }
178179 }
0 commit comments