summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Format/Format.h3
-rw-r--r--clang/lib/Format/Format.cpp4
-rw-r--r--clang/unittests/Format/FormatTest.cpp3
3 files changed, 9 insertions, 1 deletions
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 78523ea36ed..b21bfd2524f 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -65,6 +65,9 @@ struct FormatStyle {
/// the next line without calling this bin-packing.
bool AllowAllParametersOnNextLine;
+ /// \brief Allow putting the return type of a function onto its own line.
+ bool AllowReturnTypeOnItsOwnLine;
+
/// \brief If the constructor initializers don't fit on a line, put each
/// initializer on its own line.
bool ConstructorInitializerAllOnOneLineOrOnePerLine;
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 3b5dfc1abd9..21997817354 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -176,6 +176,7 @@ FormatStyle getLLVMStyle() {
LLVMStyle.SpacesBeforeTrailingComments = 1;
LLVMStyle.BinPackParameters = true;
LLVMStyle.AllowAllParametersOnNextLine = true;
+ LLVMStyle.AllowReturnTypeOnItsOwnLine = true;
LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
@@ -193,6 +194,7 @@ FormatStyle getGoogleStyle() {
GoogleStyle.SpacesBeforeTrailingComments = 2;
GoogleStyle.BinPackParameters = false;
GoogleStyle.AllowAllParametersOnNextLine = true;
+ GoogleStyle.AllowReturnTypeOnItsOwnLine = false;
GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
GoogleStyle.AllowShortIfStatementsOnASingleLine = false;
GoogleStyle.ObjCSpaceBeforeProtocolList = false;
@@ -1628,7 +1630,7 @@ private:
// Don't break at ':' if identifier before it can beak.
return false;
}
- if (Right.Type == TT_StartOfName)
+ if (Right.Type == TT_StartOfName && Style.AllowReturnTypeOnItsOwnLine)
return true;
if (Right.is(tok::colon) && Right.Type == TT_ObjCMethodExpr)
return false;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 6b9b84de269..bdc5f9a5c55 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1511,6 +1511,9 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
"TypeSpecDecl *\n"
"TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,\n"
" IdentifierIn *II, Type *T) {\n}");
+ verifyGoogleFormat(
+ "TypeSpecDecl* TypeSpecDecl::Create(\n"
+ " ASTContext& C, DeclContext* DC, SourceLocation L) {\n}");
}
TEST_F(FormatTest, LineStartsWithSpecialCharacter) {
OpenPOWER on IntegriCloud