Allow breaking between a type and name in variable declarations.
This fixes llvm.org/PR14967 and is generall necessary to avoid
situations where the column limit is exceeded. The challenge is
restricting such lines splits, otherwise clang-format suddenly starts
breaking at bad places.
Before:
ReallyLongReturnType<TemplateParam1, TemplateParam2>
ReallyReallyLongFunctionName(
const std::string &SomeParameter,
const SomeType<string,
SomeOtherTemplateParameter> &ReallyReallyLongParameterName,
const SomeType<string,
SomeOtherTemplateParameter> &AnotherLongParameterName) {}
After:
ReallyLongReturnType<TemplateParam1, TemplateParam2>
ReallyReallyLongFunctionName(
const std::string &SomeParameter,
const SomeType<string, SomeOtherTemplateParameter> &
ReallyReallyLongParameterName,
const SomeType<string, SomeOtherTemplateParameter> &
AnotherLongParameterName) {}
llvm-svn: 175999
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 2f8097c..94ac4cf 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1931,13 +1931,24 @@
verifyFormat("int(*func)(void *);");
}
-TEST_F(FormatTest, BreaksFunctionDeclarations) {
+TEST_F(FormatTest, BreaksLongDeclarations) {
verifyFormat("int *someFunction(int LoooooooooooooooooooongParam1,\n"
" int LoooooooooooooooooooongParam2) {}");
verifyFormat(
"TypeSpecDecl *\n"
"TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,\n"
" IdentifierIn *II, Type *T) {}");
+ verifyFormat("ReallyLongReturnType<TemplateParam1, TemplateParam2>\n"
+ "ReallyReallyLongFunctionName(\n"
+ " const std::string &SomeParameter,\n"
+ " const SomeType<string, SomeOtherTemplateParameter> &\n"
+ " ReallyReallyLongParameterName,\n"
+ " const SomeType<string, SomeOtherTemplateParameter> &\n"
+ " AnotherLongParameterName) {}");
+ verifyFormat(
+ "aaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaa<aaaaaaaaaaaaa, aaaaaaaaaaaa>\n"
+ "aaaaaaaaaaaaaaaaaaaaaaa;");
+
verifyGoogleFormat(
"TypeSpecDecl* TypeSpecDecl::Create(\n"
" ASTContext& C, DeclContext* DC, SourceLocation L) {}");