Author: djasper Date: Mon Jan 28 09:40:20 2013 New Revision: 173690 URL: http://llvm.org/viewvc/llvm-project?rev=173690&view=rev Log: Don't put a function's return type on its own line in Google style.
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 .. Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=173690&r1=173689&r2=173690&view=diff ============================================================================== --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Mon Jan 28 09:40:20 2013 @@ -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; Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=173690&r1=173689&r2=173690&view=diff ============================================================================== --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Mon Jan 28 09:40:20 2013 @@ -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; Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173690&r1=173689&r2=173690&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 28 09:40:20 2013 @@ -1511,6 +1511,9 @@ TEST_F(FormatTest, BreaksFunctionDeclara "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) { _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
