Skip to content

Commit 0fa29c1

Browse files
committed
Fixup FormatStyle::operator==, misc UnwrappedLineFormatter
1 parent 03ca006 commit 0fa29c1

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

clang/include/clang/Format/Format.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5511,6 +5511,7 @@ struct FormatStyle {
55115511
AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
55125512
AllowShortNamespacesOnASingleLine ==
55135513
R.AllowShortNamespacesOnASingleLine &&
5514+
AllowShortRecordOnASingleLine == R.AllowShortRecordOnASingleLine &&
55145515
AlwaysBreakBeforeMultilineStrings ==
55155516
R.AlwaysBreakBeforeMultilineStrings &&
55165517
AttributeMacros == R.AttributeMacros &&

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ class LineJoiner {
500500
: 0;
501501
}
502502

503-
auto TryMergeShortRecord = [&]() {
503+
auto TryMergeShortRecord = [&] {
504504
switch (Style.AllowShortRecordOnASingleLine) {
505505
case FormatStyle::SRS_Never:
506506
return false;
@@ -527,7 +527,7 @@ class LineJoiner {
527527
// correctly elsewhere.
528528
ShouldMerge =
529529
!Style.BraceWrapping.AfterClass ||
530-
(TryMergeShortRecord() && !Style.BraceWrapping.SplitEmptyRecord);
530+
(!Style.BraceWrapping.SplitEmptyRecord && TryMergeShortRecord());
531531
}
532532
} else if (TheLine->InPPDirective ||
533533
!TheLine->First->isOneOf(tok::kw_class, tok::kw_enum,
@@ -904,7 +904,11 @@ class LineJoiner {
904904
} else if (Limit != 0 && !Line.startsWithNamespace() &&
905905
!startsExternCBlock(Line)) {
906906
// Merge short records only when requested.
907-
if (isRecordLBrace(*Line.Last) &&
907+
if (Line.Last->isOneOf(TT_EnumLBrace, TT_RecordLBrace))
908+
return 0;
909+
910+
if (Line.Last->isOneOf(TT_ClassLBrace, TT_StructLBrace,
911+
TT_UnionLBrace) &&
908912
Style.AllowShortRecordOnASingleLine != FormatStyle::SRS_Always) {
909913
return 0;
910914
}
@@ -961,14 +965,16 @@ class LineJoiner {
961965
Limit -= 2;
962966
unsigned MergedLines = 0;
963967

964-
const bool TryMergeBlock =
965-
Style.AllowShortBlocksOnASingleLine != FormatStyle::SBS_Never;
966-
const bool TryMergeRecord =
967-
Style.AllowShortRecordOnASingleLine == FormatStyle::SRS_Always;
968-
const bool NextIsEmptyBlock = I[1]->First == I[1]->Last && I + 2 != E &&
969-
I[2]->First->is(tok::r_brace);
968+
auto TryMergeBlock = [&] {
969+
if (Style.AllowShortBlocksOnASingleLine != FormatStyle::SBS_Never ||
970+
Style.AllowShortRecordOnASingleLine == FormatStyle::SRS_Always) {
971+
return true;
972+
}
973+
return I[1]->First == I[1]->Last && I + 2 != E &&
974+
I[2]->First->is(tok::r_brace);
975+
};
970976

971-
if (TryMergeBlock || TryMergeRecord || NextIsEmptyBlock) {
977+
if (TryMergeBlock()) {
972978
MergedLines = tryMergeSimpleBlock(I + 1, E, Limit);
973979
// If we managed to merge the block, count the statement header, which
974980
// is on a separate line.

0 commit comments

Comments
 (0)