[clang-tools-extra] Apply format only if --format is specified (PR #70801)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 31 06:31:08 PDT 2023


https://github.com/kuganv created https://github.com/llvm/llvm-project/pull/70801

clang-apply-replacements is now applying format even when --format is not specified.  Methods like createReplacementsForHeaders only takes the Spec.Style and would re-order the headers even when it was not requested. The fix is to set up Spec.Style only if --format is provided.

>From 1d50caf93e4b8fb3fc9e24fe7fba83b328f08d57 Mon Sep 17 00:00:00 2001
From: Kugan <34810920+kuganv at users.noreply.github.com>
Date: Tue, 31 Oct 2023 12:12:10 +0000
Subject: [PATCH] Apply format only if --format is specified

clang-apply-replacements is now applying format even when --format is specified.  This because, methods like createReplacementsForHeaders only takes the Spec.Style and would re-order the headers even when it was not requested. The fix is to set up Spec.Style only if --format is provided.
---
 .../tool/ClangApplyReplacementsMain.cpp                         | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
index 9331898bf2570e6..68b5743c6540f8a 100644
--- a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -141,9 +141,9 @@ int main(int argc, char **argv) {
 
   tooling::ApplyChangesSpec Spec;
   Spec.Cleanup = true;
-  Spec.Style = FormatStyle;
   Spec.Format = DoFormat ? tooling::ApplyChangesSpec::kAll
                          : tooling::ApplyChangesSpec::kNone;
+  Spec.Style = DoFormat ? FormatStyle : format::getNoStyle();
 
   for (const auto &FileChange : Changes) {
     FileEntryRef Entry = FileChange.first;



More information about the cfe-commits mailing list