Skip to content

Commit

Permalink
[clang-format] Don't rewrite the input file if already formatted
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
owenca authored and tru committed Feb 21, 2023
1 parent babeb69 commit b98d959
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
continue;
if (Start > 0)
Location = Location.getLocWithOffset(Start);
cantFail(Result.add(tooling::Replacement(SourceMgr, Location, Length,
format(Text, DigitsPerGroup))));
if (const auto &Formatted = format(Text, DigitsPerGroup);
Formatted != Text) {
cantFail(Result.add(
tooling::Replacement(SourceMgr, Location, Length, Formatted)));
}
}

return {Result, 0};
Expand Down

0 comments on commit b98d959

Please sign in to comment.