State.Stack.back().ObjCSelectorNameFound &&
State.Stack.back().BreakBeforeParameter)
return true;
- if (Current.Type == TT_CtorInitializerColon &&
- (!Style.AllowShortFunctionsOnASingleLine ||
- Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0))
- return true;
if (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0 &&
!Current.isTrailingComment())
return true;
(State.Stack.back().BreakBeforeParameter &&
State.Stack.back().ContainsUnwrappedBuilder)))
return true;
+
+ // The following could be precomputed as they do not depend on the state.
+ // However, as they should take effect only if the UnwrappedLine does not fit
+ // into the ColumnLimit, they are checked here in the ContinuationIndenter.
+ if (Previous.BlockKind == BK_Block && Previous.is(tok::l_brace) &&
+ !Current.isOneOf(tok::r_brace, tok::comment))
+ return true;
+ if (Current.Type == TT_CtorInitializerColon &&
+ (!Style.AllowShortFunctionsOnASingleLine ||
+ Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0))
+ return true;
+
return false;
}
Style.BreakConstructorInitializersBeforeComma &&
!Style.ConstructorInitializerAllOnOneLineOrOnePerLine) {
return true;
- } else if (Right.Previous->BlockKind == BK_Block &&
- Right.Previous->isNot(tok::r_brace) && Right.isNot(tok::r_brace)) {
- return true;
} else if (Right.is(tok::l_brace) && (Right.BlockKind == BK_Block)) {
return Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
Style.BreakBeforeBraces == FormatStyle::BS_GNU;
verifyFormat("enum X f() {\n a();\n return 42;\n}");
verifyFormat("enum {\n"
" Bar = Foo<int, int>::value\n"
- "};");
+ "};",
+ getLLVMStyleWithColumns(30));
+
+ verifyFormat("enum ShortEnum { A, B, C };");
}
TEST_F(FormatTest, FormatsEnumsWithErrors) {
verifyFormat("enum Type {\n"
- " One = 0;\n" // These semicolons should be commas.
+ " One = 0; // These semicolons should be commas.\n"
" Two = 1;\n"
"};");
verifyFormat("namespace n {\n"
"enum Type {\n"
" One,\n"
- " Two,\n" // missing };
+ " Two, // missing };\n"
" int i;\n"
"}\n"
"void g() {}");
TEST_F(FormatTest, FormatsEnumTypes) {
verifyFormat("enum X : int {\n"
- " A,\n"
- " B\n"
- "};");
- verifyFormat("enum X : std::uint32_t {\n"
- " A,\n"
+ " A, // Force multiple lines.\n"
" B\n"
"};");
+ verifyFormat("enum X : int { A, B };");
+ verifyFormat("enum X : std::uint32_t { A, B };");
}
TEST_F(FormatTest, FormatsBitfields) {
"};",
Tab);
verifyFormat("enum A {\n"
- "\ta1,\n"
+ "\ta1, // Force multiple lines\n"
"\ta2,\n"
"\ta3\n"
"};",