Skip to content

Commit ea3aca8

Browse files
committed
Fixes issue with Allman BreakBeforeBraces for Objective C @interface
Before: @interface BSApplicationController () { @Private id _extraIvar; } @EnD After: @interface BSApplicationController () { @Private id _extraIvar; } @EnD llvm-svn: 207849
1 parent 56c5822 commit ea3aca8

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,9 +1291,12 @@ void UnwrappedLineParser::parseObjCInterfaceOrImplementation() {
12911291
if (FormatTok->Tok.is(tok::less))
12921292
parseObjCProtocolList();
12931293

1294-
// If instance variables are present, keep the '{' on the first line too.
1295-
if (FormatTok->Tok.is(tok::l_brace))
1294+
if (FormatTok->Tok.is(tok::l_brace)) {
1295+
if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
1296+
Style.BreakBeforeBraces == FormatStyle::BS_GNU)
1297+
addUnwrappedLine();
12961298
parseBlock(/*MustBeDeclaration=*/true);
1299+
}
12971300

12981301
// With instance variables, this puts '}' on its own line. Without instance
12991302
// variables, this ends the @interface line.

clang/unittests/Format/FormatTest.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7444,6 +7444,14 @@ TEST_F(FormatTest, AllmanBraceBreaking) {
74447444
"}\n",
74457445
BreakBeforeBrace);
74467446

7447+
verifyFormat("@interface BSApplicationController ()\n"
7448+
"{\n"
7449+
"@private\n"
7450+
" id _extraIvar;\n"
7451+
"}\n"
7452+
"@end\n",
7453+
BreakBeforeBrace);
7454+
74477455
BreakBeforeBrace.ColumnLimit = 19;
74487456
verifyFormat("void f() { int i; }", BreakBeforeBrace);
74497457
BreakBeforeBrace.ColumnLimit = 18;
@@ -7564,6 +7572,14 @@ TEST_F(FormatTest, GNUBraceBreaking) {
75647572
" Y = 0,\n"
75657573
"}\n",
75667574
GNUBraceStyle);
7575+
7576+
verifyFormat("@interface BSApplicationController ()\n"
7577+
"{\n"
7578+
"@private\n"
7579+
" id _extraIvar;\n"
7580+
"}\n"
7581+
"@end\n",
7582+
GNUBraceStyle);
75677583
}
75687584
TEST_F(FormatTest, CatchExceptionReferenceBinding) {
75697585
verifyFormat("void f() {\n"

0 commit comments

Comments
 (0)