/// the next line even if \c BinPackParameters is \c false.
bool AllowAllParametersOfDeclarationOnNextLine;
- /// \brief Allow putting the return type of a function onto its own line.
- bool AllowReturnTypeOnItsOwnLine;
+ /// \brief Penalty for putting the return type of a function onto its own
+ /// line.
+ unsigned PenaltyReturnTypeOnItsOwnLine;
/// \brief If the constructor initializers don't fit on a line, put each
/// initializer on its own line.
LLVMStyle.SpacesBeforeTrailingComments = 1;
LLVMStyle.BinPackParameters = true;
LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
- LLVMStyle.AllowReturnTypeOnItsOwnLine = true;
LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
LLVMStyle.PenaltyExcessCharacter = 1000000;
+ LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 5;
return LLVMStyle;
}
GoogleStyle.SpacesBeforeTrailingComments = 2;
GoogleStyle.BinPackParameters = false;
GoogleStyle.AllowAllParametersOfDeclarationOnNextLine = true;
- GoogleStyle.AllowReturnTypeOnItsOwnLine = false;
GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
GoogleStyle.AllowShortIfStatementsOnASingleLine = false;
GoogleStyle.ObjCSpaceBeforeProtocolList = false;
GoogleStyle.PenaltyExcessCharacter = 1000000;
+ GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 100;
return GoogleStyle;
}
reconstructPath(State, Current->Previous);
DEBUG({
if (Current->NewLine) {
- llvm::errs() << "Penalty for splitting before "
- << Current->State.NextToken->FormatTok.Tok.getName()
- << ": " << Current->State.NextToken->SplitPenalty << "\n";
+ llvm::errs()
+ << "Penalty for splitting before "
+ << Current->Previous->State.NextToken->FormatTok.Tok.getName()
+ << ": " << Current->Previous->State.NextToken->SplitPenalty << "\n";
}
});
addTokenToState(Current->NewLine, false, State);
const AnnotatedToken &Left = *Tok.Parent;
const AnnotatedToken &Right = Tok;
+ if (Right.Type == TT_StartOfName)
+ return Style.PenaltyReturnTypeOnItsOwnLine;
if (Left.is(tok::l_brace) && Right.isNot(tok::l_brace))
return 50;
if (Left.is(tok::equal) && Right.is(tok::l_brace))
bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
const AnnotatedToken &Right) {
const AnnotatedToken &Left = *Right.Parent;
- if (Right.Type == TT_StartOfName && Style.AllowReturnTypeOnItsOwnLine)
+ if (Right.Type == TT_StartOfName)
return true;
if (Right.is(tok::colon) && Right.Type == TT_ObjCMethodExpr)
return false;
verifyGoogleFormat(
"TypeSpecDecl* TypeSpecDecl::Create(\n"
" ASTContext& C, DeclContext* DC, SourceLocation L) {\n}");
+ verifyGoogleFormat(
+ "some_namespace::LongReturnType\n"
+ "long_namespace::SomeVeryLongClass::SomeVeryLongFunction(\n"
+ " int first_long_parameter, int second_parameter) {\n}");
+
+ verifyGoogleFormat("template <typename T>\n"
+ "aaaaaaaa::aaaaa::aaaaaa<T, aaaaaaaaaaaaaaaaaaaaaaaaa>\n"
+ "aaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaa() {\n}");
}
TEST_F(FormatTest, LineStartsWithSpecialCharacter) {