Skip to content

Commit b98d959

Browse files
owencatru
authored andcommitted
[clang-format] Don't rewrite the input file if already formatted
If IntegerLiteralSeparator is set but the integer literals are already formatted, don't rewrite the input file. Fixes #60651. Differential Revision: https://reviews.llvm.org/D143831 (cherry picked from commit b4243bb)
1 parent babeb69 commit b98d959

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

clang/lib/Format/IntegerLiteralSeparatorFixer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
132132
continue;
133133
if (Start > 0)
134134
Location = Location.getLocWithOffset(Start);
135-
cantFail(Result.add(tooling::Replacement(SourceMgr, Location, Length,
136-
format(Text, DigitsPerGroup))));
135+
if (const auto &Formatted = format(Text, DigitsPerGroup);
136+
Formatted != Text) {
137+
cantFail(Result.add(
138+
tooling::Replacement(SourceMgr, Location, Length, Formatted)));
139+
}
137140
}
138141

139142
return {Result, 0};

0 commit comments

Comments
 (0)