=?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com>, =?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com>, =?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com>, =?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com>, =?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com>, =?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com>, =?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com>, =?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com>, =?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com>, =?utf-8?q?Tomáš?= Slanina <itzexpoe...@gmail.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/154...@github.com>
================ @@ -485,20 +493,33 @@ class LineJoiner { : 0; } + const bool TryMergeShortRecord = [this, &NextLine]() { + switch (Style.AllowShortRecordOnASingleLine) { + case FormatStyle::SRS_Never: + return false; + case FormatStyle::SRS_EmptyIfAttached: + case FormatStyle::SRS_Empty: + return NextLine.First->is(tok::r_brace); + case FormatStyle::SRS_Always: + return true; + } + }() && !Style.BraceWrapping.SplitEmptyRecord; + if (TheLine->Last->is(tok::l_brace)) { bool ShouldMerge = false; // Try to merge records. if (TheLine->Last->is(TT_EnumLBrace)) { ShouldMerge = Style.AllowShortEnumsOnASingleLine; } else if (TheLine->Last->is(TT_CompoundRequirementLBrace)) { ShouldMerge = Style.AllowShortCompoundRequirementOnASingleLine; - } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace)) { - // NOTE: We use AfterClass (whereas AfterStruct exists) for both classes - // and structs, but it seems that wrapping is still handled correctly - // elsewhere. - ShouldMerge = !Style.BraceWrapping.AfterClass || - (NextLine.First->is(tok::r_brace) && - !Style.BraceWrapping.SplitEmptyRecord); + } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace, + TT_UnionLBrace)) { + if (Style.AllowShortRecordOnASingleLine > FormatStyle::SRS_Never) { + // NOTE: We use AfterClass (whereas AfterStruct exists) for both + // classes and structs, but it seems that wrapping is still handled + // correctly elsewhere. + ShouldMerge = !Style.BraceWrapping.AfterClass || TryMergeShortRecord; ---------------- owenca wrote: As `ShouldMerge` is set to `false` initially, the gist of the logic here is: ``` If not SRS_Never and (not AfterClass or (lambda and not SplitEmptyRecord)) set ShouldMerge to true ``` And the lambda also has the `SRS_Never` case, which returns `false`? https://github.com/llvm/llvm-project/pull/154580 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits