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
  • Loading branch information
owenca committed Feb 14, 2023
1 parent ed3e3ee commit b4243bb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
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 b4243bb

Please sign in to comment.