@@ -753,6 +753,7 @@ BreakableLineCommentSection::BreakableLineCommentSection(
753
753
assert (Tok.is (TT_LineComment) &&
754
754
" line comment section must start with a line comment" );
755
755
FormatToken *LineTok = nullptr ;
756
+ const int Minimum = Style.SpacesInLineCommentPrefix .Minimum ;
756
757
// How many spaces we changed in the first line of the section, this will be
757
758
// applied in all following lines
758
759
int FirstLineSpaceChange = 0 ;
@@ -775,7 +776,7 @@ BreakableLineCommentSection::BreakableLineCommentSection(
775
776
Lines[i] = Lines[i].ltrim (Blanks);
776
777
StringRef IndentPrefix = getLineCommentIndentPrefix (Lines[i], Style);
777
778
OriginalPrefix[i] = IndentPrefix;
778
- const unsigned SpacesInPrefix = llvm::count (IndentPrefix, ' ' );
779
+ const int SpacesInPrefix = llvm::count (IndentPrefix, ' ' );
779
780
780
781
// On the first line of the comment section we calculate how many spaces
781
782
// are to be added or removed, all lines after that just get only the
@@ -784,12 +785,11 @@ BreakableLineCommentSection::BreakableLineCommentSection(
784
785
// e.g. from "///" to "//".
785
786
if (i == 0 || OriginalPrefix[i].rtrim (Blanks) !=
786
787
OriginalPrefix[i - 1 ].rtrim (Blanks)) {
787
- if (SpacesInPrefix < Style.SpacesInLineCommentPrefix .Minimum &&
788
- Lines[i].size () > IndentPrefix.size () &&
788
+ if (SpacesInPrefix < Minimum && Lines[i].size () > IndentPrefix.size () &&
789
789
isAlphanumeric (Lines[i][IndentPrefix.size ()])) {
790
- FirstLineSpaceChange =
791
- Style. SpacesInLineCommentPrefix . Minimum - SpacesInPrefix;
792
- } else if (SpacesInPrefix > Style.SpacesInLineCommentPrefix .Maximum ) {
790
+ FirstLineSpaceChange = Minimum - SpacesInPrefix;
791
+ } else if ( static_cast < unsigned >( SpacesInPrefix) >
792
+ Style.SpacesInLineCommentPrefix .Maximum ) {
793
793
FirstLineSpaceChange =
794
794
Style.SpacesInLineCommentPrefix .Maximum - SpacesInPrefix;
795
795
} else {
@@ -800,10 +800,9 @@ BreakableLineCommentSection::BreakableLineCommentSection(
800
800
if (Lines[i].size () != IndentPrefix.size ()) {
801
801
PrefixSpaceChange[i] = FirstLineSpaceChange;
802
802
803
- if (SpacesInPrefix + PrefixSpaceChange[i] <
804
- Style.SpacesInLineCommentPrefix .Minimum ) {
805
- PrefixSpaceChange[i] += Style.SpacesInLineCommentPrefix .Minimum -
806
- (SpacesInPrefix + PrefixSpaceChange[i]);
803
+ if (SpacesInPrefix + PrefixSpaceChange[i] < Minimum) {
804
+ PrefixSpaceChange[i] +=
805
+ Minimum - (SpacesInPrefix + PrefixSpaceChange[i]);
807
806
}
808
807
809
808
assert (Lines[i].size () > IndentPrefix.size ());
0 commit comments