]> granicus.if.org Git - clang/commitdiff
Don't put a function's return type on its own line in Google style.
authorDaniel Jasper <djasper@google.com>
Mon, 28 Jan 2013 15:40:20 +0000 (15:40 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 28 Jan 2013 15:40:20 +0000 (15:40 +0000)
This would be against the style guide:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Function_Declarations_and_Definitions#Function_Declarations_and_Definitions

Not sure what to do as a last resort if the function signature does not
fit onto a single line in Google style ..

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173690 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Format/Format.h
lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 78523ea36ed18bd506bd99658d558bc401f32ec0..b21bfd2524f91d9521aae164372824d14023c7ff 100644 (file)
@@ -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;
index 3b5dfc1abd9f19c7cd2c1f78bbd42ba4b2789a3b..21997817354161c6cd9d1e5442ca2aa17c7d399c 100644 (file)
@@ -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;
index 6b9b84de2695113bf5b0b4fdb6b861999f8c8446..bdc5f9a5c55d16cd5acb2939b442e6469dd32f19 100644 (file)
@@ -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) {