Skip to content

Commit d35768a

Browse files
committed
Fix incorrect merge check
1 parent 86073c9 commit d35768a

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class LineJoiner {
271271
TT_UnionLBrace) &&
272272
NextLine.First == NextLine.Last && I + 2 != E &&
273273
!I[2]->First->is(tok::r_brace) &&
274-
Style.AllowShortRecordOnASingleLine != FormatStyle::SRS_Never) {
274+
Style.AllowShortRecordOnASingleLine == FormatStyle::SRS_Always) {
275275
if (unsigned MergedLines = tryMergeSimpleBlock(I, E, Limit))
276276
return MergedLines;
277277
}
@@ -282,9 +282,7 @@ class LineJoiner {
282282
TheLine->First == TheLine->Last) {
283283
const bool EmptyBlock = NextLine.First->is(tok::r_brace);
284284

285-
const FormatToken *Tok = PreviousLine->First;
286-
if (Tok && Tok->is(tok::comment))
287-
Tok = Tok->getNextNonComment();
285+
const FormatToken *Tok = PreviousLine->getFirstNonComment();
288286

289287
if (Tok && Tok->getNamespaceToken()) {
290288
return !Style.BraceWrapping.SplitEmptyNamespace && EmptyBlock
@@ -294,6 +292,7 @@ class LineJoiner {
294292

295293
if (Tok && Tok->is(tok::kw_typedef))
296294
Tok = Tok->getNextNonComment();
295+
297296
if (Tok && Tok->isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union,
298297
tok::kw_extern, Keywords.kw_interface)) {
299298
return (EmptyBlock && !Style.BraceWrapping.SplitEmptyRecord) ||

clang/unittests/Format/FormatTest.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15360,9 +15360,6 @@ TEST_F(FormatTest, AllowShortRecordOnASingleLine) {
1536015360
verifyFormat("class foo\n"
1536115361
"{};",
1536215362
Style);
15363-
Style.BraceWrapping.SplitEmptyRecord = true;
15364-
Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;
15365-
verifyFormat("class foo\n{ int i; };", Style);
1536615363

1536715364
Style = getLLVMStyle();
1536815365
Style.AllowShortRecordOnASingleLine = FormatStyle::SRS_Empty;
@@ -15398,6 +15395,22 @@ TEST_F(FormatTest, AllowShortRecordOnASingleLine) {
1539815395
Style);
1539915396
Style.BraceWrapping.SplitEmptyRecord = false;
1540015397
verifyFormat("class foo {};", Style);
15398+
15399+
Style = getLLVMStyle();
15400+
Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;
15401+
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
15402+
Style.BraceWrapping.AfterClass = true;
15403+
15404+
Style.AllowShortRecordOnASingleLine = FormatStyle::SRS_Never;
15405+
verifyFormat("class foo\n"
15406+
"{ int i; };",
15407+
Style);
15408+
Style.AllowShortRecordOnASingleLine = FormatStyle::SRS_Empty;
15409+
verifyFormat("class foo\n"
15410+
"{ int i; };",
15411+
Style);
15412+
Style.AllowShortRecordOnASingleLine = FormatStyle::SRS_Always;
15413+
verifyFormat("class foo { int i; };", Style);
1540115414
}
1540215415

1540315416
TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {

0 commit comments

Comments
 (0)