if (I + 1 == E || (I + 1)->Type == LT_Invalid)
return;
- if (I->Last->is(tok::l_brace) &&
- Style.BreakBeforeBraces == FormatStyle::BS_Attach) {
+ if (I->Last->is(tok::l_brace)) {
tryMergeSimpleBlock(I, E, Limit);
} else if (I->First.is(tok::kw_if)) {
tryMergeSimpleIf(I, E, Limit);
void tryMergeSimpleBlock(std::vector<AnnotatedLine>::iterator &I,
std::vector<AnnotatedLine>::iterator E,
unsigned Limit) {
+ // No merging if the brace already is on the next line.
+ if (Style.BreakBeforeBraces != FormatStyle::BS_Attach)
+ return;
+
// First, check that the current line allows merging. This is the case if
// we're not in a control flow statement and the last token is an opening
// brace.
AnnotatedLine &Line = *I;
if (Line.First.isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::r_brace,
tok::kw_else, tok::kw_try, tok::kw_catch,
- tok::kw_for,
+ tok::kw_for, tok::kw_namespace,
// This gets rid of all ObjC @ keywords and methods.
tok::at, tok::minus, tok::plus))
return;
}
TEST_F(FormatTest, ParsesCommentsAdjacentToPPDirectives) {
- EXPECT_EQ("namespace {}\n// Test\n#define A",
+ EXPECT_EQ("namespace {\n}\n// Test\n#define A",
format("namespace {}\n // Test\n#define A"));
- EXPECT_EQ("namespace {}\n/* Test */\n#define A",
+ EXPECT_EQ("namespace {\n}\n/* Test */\n#define A",
format("namespace {}\n /* Test */\n#define A"));
- EXPECT_EQ("namespace {}\n/* Test */ #define A",
+ EXPECT_EQ("namespace {\n}\n/* Test */ #define A",
format("namespace {}\n /* Test */ #define A"));
}
" return\n"
"}",
format("void f ( ) { if ( a ) return }"));
- EXPECT_EQ("namespace N { void f() }", format("namespace N { void f() }"));
+ EXPECT_EQ("namespace N {\n"
+ "void f()\n"
+ "}",
+ format("namespace N { void f() }"));
EXPECT_EQ("namespace N {\n"
"void f() {}\n"
"void g()\n"