[clang-tools-extra] [clang-tidy] Detect string literals in macros in modernize-raw-string… (PR #133636)

via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 30 05:31:27 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp clang-tools-extra/test/clang-tidy/checkers/modernize/raw-string-literal.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
index 1be0d6cc2..b7fad9193 100644
--- a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -156,7 +156,8 @@ static bool compareStringLength(StringRef Replacement,
                                 const SourceManager &SM,
                                 const LangOptions &LangOpts) {
   return Replacement.size() <=
-         Lexer::MeasureTokenLength(SM.getSpellingLoc(Literal->getBeginLoc()), SM, LangOpts);
+         Lexer::MeasureTokenLength(SM.getSpellingLoc(Literal->getBeginLoc()),
+                                   SM, LangOpts);
 }
 
 void RawStringLiteralCheck::check(const MatchFinder::MatchResult &Result) {
@@ -172,9 +173,10 @@ void RawStringLiteralCheck::check(const MatchFinder::MatchResult &Result) {
         compareStringLength(Replacement, Literal, SM, LangOpts)) {
       diag(Literal->getBeginLoc(),
            "escaped string literal can be written as a raw string literal")
-          << FixItHint::CreateReplacement(SourceRange(SM.getSpellingLoc(Literal->getBeginLoc()),
-                                                      SM.getSpellingLoc(Literal->getEndLoc())),
-                                          Replacement);
+          << FixItHint::CreateReplacement(
+                 SourceRange(SM.getSpellingLoc(Literal->getBeginLoc()),
+                             SM.getSpellingLoc(Literal->getEndLoc())),
+                 Replacement);
     }
   }
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/133636


More information about the cfe-commits mailing list