With option enabled (e.g. in Google-style):
template <typename T>
void f() {}
With option disabled:
template <typename T> void f() {}
Enabling this for Google-style and Chromium-style, not sure which other
styles would prefer that.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182849
91177308-0d34-0410-b5e6-
96231b3b80d8
/// \brief The number of characters to use for indentation.
unsigned IndentWidth;
+ /// \brief If \c true, always break after the \c template<...> of a template
+ /// declaration.
+ bool AlwaysBreakTemplateDeclarations;
+
/// \brief If true, \c IndentWidth consecutive spaces will be replaced with
/// tab characters.
bool UseTab;
R.AllowAllParametersOfDeclarationOnNextLine &&
AllowShortIfStatementsOnASingleLine ==
R.AllowShortIfStatementsOnASingleLine &&
+ AlwaysBreakTemplateDeclarations ==
+ R.AlwaysBreakTemplateDeclarations &&
BinPackParameters == R.BinPackParameters &&
BreakBeforeBraces == R.BreakBeforeBraces &&
ColumnLimit == R.ColumnLimit &&
PointerBindsToType == R.PointerBindsToType &&
SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
SpacesInBracedLists == R.SpacesInBracedLists &&
- Standard == R.Standard &&
- UseTab == R.UseTab;
+ Standard == R.Standard && UseTab == R.UseTab;
}
};
Style.AllowShortIfStatementsOnASingleLine);
IO.mapOptional("AllowShortLoopsOnASingleLine",
Style.AllowShortLoopsOnASingleLine);
+ IO.mapOptional("AlwaysBreakTemplateDeclarations",
+ Style.AlwaysBreakTemplateDeclarations);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("ColumnLimit", Style.ColumnLimit);
IO.mapOptional("ConstructorInitializerAllOnOneLineOrOnePerLine",
LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
LLVMStyle.AllowShortLoopsOnASingleLine = false;
+ LLVMStyle.AlwaysBreakTemplateDeclarations = false;
LLVMStyle.BinPackParameters = true;
LLVMStyle.ColumnLimit = 80;
LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
GoogleStyle.AllowAllParametersOfDeclarationOnNextLine = true;
GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
GoogleStyle.AllowShortLoopsOnASingleLine = true;
+ GoogleStyle.AlwaysBreakTemplateDeclarations = true;
GoogleStyle.BinPackParameters = true;
GoogleStyle.ColumnLimit = 80;
GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
Current->Parent->is(tok::string_literal) &&
Current->Children[0].is(tok::string_literal)) {
Current->MustBreakBefore = true;
+ } else if (Current->Parent->ClosesTemplateDeclaration &&
+ Style.AlwaysBreakTemplateDeclarations) {
+ Current->MustBreakBefore = true;
} else {
Current->MustBreakBefore = false;
}
verifyFormat("a<aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa>(\n"
" a(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa));");
+
+ verifyFormat("template <typename T> class C {\n};");
+ verifyFormat("template <typename T> void f();");
+ verifyFormat("template <typename T> void f() {}");
+
+ FormatStyle AlwaysBreak = getLLVMStyle();
+ AlwaysBreak.AlwaysBreakTemplateDeclarations = true;
+ verifyFormat("template <typename T>\nclass C {\n};", AlwaysBreak);
+ verifyFormat("template <typename T>\nvoid f();", AlwaysBreak);
+ verifyFormat("template <typename T>\nvoid f() {}", AlwaysBreak);
}
TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {
CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
+ CHECK_PARSE_BOOL(AlwaysBreakTemplateDeclarations);
CHECK_PARSE_BOOL(BinPackParameters);
CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
CHECK_PARSE_BOOL(DerivePointerBinding);