Skip to content

Commit 6bf6630

Browse files
owencatstellar
authored andcommitted
[clang-format] Don't format already formatted integer literals
Fixes a bug in IntegerLiteralSeparatorFixer::checkSeparator() so that only unformatted integer literals will be formatted. Differential Revision: https://reviews.llvm.org/D146501 (cherry picked from commit 5b5c49a)
1 parent 7b13394 commit 6bf6630

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

clang/lib/Format/IntegerLiteralSeparatorFixer.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,12 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
136136
DigitsPerGroup = Hex;
137137
if (DigitsPerGroup > 0 && checkSeparator(Text, DigitsPerGroup))
138138
continue;
139+
const auto &Formatted = format(Text, DigitsPerGroup);
140+
assert(Formatted != Text);
139141
if (Start > 0)
140142
Location = Location.getLocWithOffset(Start);
141-
if (const auto &Formatted = format(Text, DigitsPerGroup);
142-
Formatted != Text) {
143-
cantFail(Result.add(
144-
tooling::Replacement(SourceMgr, Location, Length, Formatted)));
145-
}
143+
cantFail(Result.add(
144+
tooling::Replacement(SourceMgr, Location, Length, Formatted)));
146145
}
147146

148147
return {Result, 0};
@@ -159,9 +158,9 @@ bool IntegerLiteralSeparatorFixer::checkSeparator(
159158
return false;
160159
I = 0;
161160
} else {
162-
++I;
163161
if (I == DigitsPerGroup)
164162
return false;
163+
++I;
165164
}
166165
}
167166

0 commit comments

Comments
 (0)