Skip to content

Commit e1062d7

Browse files
committed
Fixup ShouldBreakBeforeBrace
1 parent 6f11ac2 commit e1062d7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -949,15 +949,14 @@ static bool isIIFE(const UnwrappedLine &Line,
949949

950950
static bool ShouldBreakBeforeBrace(const FormatStyle &Style,
951951
const FormatToken &InitialToken,
952-
const FormatToken &NextToken) {
952+
bool IsEmptyBlock) {
953953
tok::TokenKind Kind = InitialToken.Tok.getKind();
954954
if (InitialToken.is(TT_NamespaceMacro))
955955
Kind = tok::kw_namespace;
956956

957-
bool IsEmptyBlock = NextToken.is(tok::r_brace);
958957
bool WrapRecordAllowed =
959-
!(IsEmptyBlock && Style.AllowShortRecordOnASingleLine >
960-
FormatStyle::SRS_EmptyIfAttached) ||
958+
!IsEmptyBlock ||
959+
Style.AllowShortRecordOnASingleLine < FormatStyle::SRS_Empty ||
961960
Style.BraceWrapping.SplitEmptyRecord;
962961

963962
switch (Kind) {
@@ -3200,8 +3199,10 @@ void UnwrappedLineParser::parseNamespace() {
32003199
if (FormatTok->is(tok::l_brace)) {
32013200
FormatTok->setFinalizedType(TT_NamespaceLBrace);
32023201

3203-
if (ShouldBreakBeforeBrace(Style, InitialToken, *Tokens->peekNextToken()))
3202+
if (ShouldBreakBeforeBrace(Style, InitialToken,
3203+
Tokens->peekNextToken()->is(tok::r_brace))) {
32043204
addUnwrappedLine();
3205+
}
32053206

32063207
unsigned AddLevels =
32073208
Style.NamespaceIndentation == FormatStyle::NI_All ||
@@ -3865,7 +3866,8 @@ bool UnwrappedLineParser::parseEnum() {
38653866
}
38663867

38673868
if (!Style.AllowShortEnumsOnASingleLine &&
3868-
ShouldBreakBeforeBrace(Style, InitialToken, *Tokens->peekNextToken())) {
3869+
ShouldBreakBeforeBrace(Style, InitialToken,
3870+
Tokens->peekNextToken()->is(tok::r_brace))) {
38693871
addUnwrappedLine();
38703872
}
38713873
// Parse enum body.
@@ -4160,8 +4162,10 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr, bool IsJavaRecord) {
41604162
if (ParseAsExpr) {
41614163
parseChildBlock();
41624164
} else {
4163-
if (ShouldBreakBeforeBrace(Style, InitialToken, *Tokens->peekNextToken()))
4165+
if (ShouldBreakBeforeBrace(Style, InitialToken,
4166+
Tokens->peekNextToken()->is(tok::r_brace))) {
41644167
addUnwrappedLine();
4168+
}
41654169

41664170
unsigned AddLevels = Style.IndentAccessModifiers ? 2u : 1u;
41674171
parseBlock(/*MustBeDeclaration=*/true, AddLevels, /*MunchSemi=*/false);

0 commit comments

Comments
 (0)