summaryrefslogtreecommitdiffstats
path: root/clang/tools/clang-format/ClangFormat.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-08-10 09:32:23 +0000
committerEric Liu <ioeric@google.com>2016-08-10 09:32:23 +0000
commita992afe80977bedcbe85a1140efcc8fd28878df1 (patch)
tree5b34c4e69094e79437a4629efb4484e28a3c5e36 /clang/tools/clang-format/ClangFormat.cpp
parente4195dc8039d0a9e422dd64e44021b05c05a541e (diff)
downloadbcm5719-llvm-a992afe80977bedcbe85a1140efcc8fd28878df1.tar.gz
bcm5719-llvm-a992afe80977bedcbe85a1140efcc8fd28878df1.zip
Make clang-format remove duplicate headers when sorting #includes.
Summary: When sorting #includes, #include directives that have the same text will be deduplicated when sorting #includes, and only the first #include in the duplicate #includes remains. If the `Cursor` is provided and put on a deleted #include, it will be put on the remaining #include in the duplicate #includes. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D23274 llvm-svn: 278206
Diffstat (limited to 'clang/tools/clang-format/ClangFormat.cpp')
-rw-r--r--clang/tools/clang-format/ClangFormat.cpp5
1 files changed, 2 insertions, 3 deletions
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index 3b893e04b32..c09723928b7 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -260,9 +260,8 @@ static bool format(StringRef FileName) {
llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n";
return true;
}
- for (const auto &R : Replaces)
- Ranges.push_back({R.getOffset(), R.getLength()});
-
+ // Get new affected ranges after sorting `#includes`.
+ Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges);
bool IncompleteFormat = false;
Replacements FormatChanges = reformat(FormatStyle, *ChangedCode, Ranges,
AssumedFileName, &IncompleteFormat);
OpenPOWER on IntegriCloud