clang-format: Don't break after very short return types.

Before:
  void
  SomeFunction(int parameter);

After:
  void SomeFunction(
      int parameter);

(Unless AlwaysBreakAfterDefinitionReturnType after type is set).

llvm-svn: 220686
This commit is contained in:
Daniel Jasper 2014-10-27 17:13:59 +00:00
parent 1f060a8552
commit e068ac77a2
2 changed files with 16 additions and 10 deletions

View File

@ -122,6 +122,12 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
State.Stack[State.Stack.size() - 2].HasMultipleNestedBlocks)
return false;
// Don't break after very short return types (e.g. "void") as that is often
// unexpected.
if (Current.Type == TT_FunctionDeclarationName &&
!Style.AlwaysBreakAfterDefinitionReturnType && State.Column < 6)
return false;
return !State.Stack.back().NoLineBreak;
}

View File

@ -1207,8 +1207,8 @@ TEST_F(FormatTest, CorrectlyHandlesLengthOfBlockComments) {
}
TEST_F(FormatTest, DontBreakNonTrailingBlockComments) {
EXPECT_EQ("void\n"
"ffffffffff(int aaaaa /* test */);",
EXPECT_EQ("void ffffffffff(\n"
" int aaaaa /* test */);",
format("void ffffffffff(int aaaaa /* test */);",
getLLVMStyleWithColumns(35)));
}
@ -1258,11 +1258,11 @@ TEST_F(FormatTest, SplitsLongCxxComments) {
format("// A comment before a macro definition\n"
"#define a b",
getLLVMStyleWithColumns(20)));
EXPECT_EQ("void\n"
"ffffff(int aaaaaaaaa, // wwww\n"
" int bbbbbbbbbb, // xxxxxxx\n"
" // yyyyyyyyyy\n"
" int c, int d, int e) {}",
EXPECT_EQ("void ffffff(\n"
" int aaaaaaaaa, // wwww\n"
" int bbbbbbbbbb, // xxxxxxx\n"
" // yyyyyyyyyy\n"
" int c, int d, int e) {}",
format("void ffffff(\n"
" int aaaaaaaaa, // wwww\n"
" int bbbbbbbbbb, // xxxxxxx yyyyyyyyyy\n"
@ -3538,8 +3538,8 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
// they are not function-like.
FormatStyle Style = getGoogleStyle();
Style.ColumnLimit = 47;
verifyFormat("void\n"
"someLongFunction(int someLongParameter) const {\n}",
verifyFormat("void someLongFunction(\n"
" int someLoooooooooooooongParameter) const {\n}",
getLLVMStyleWithColumns(47));
verifyFormat("LoooooongReturnType\n"
"someLoooooooongFunction() const {}",
@ -7400,7 +7400,7 @@ TEST_F(FormatTest, ConfigurableIndentWidth) {
}
TEST_F(FormatTest, ConfigurableFunctionDeclarationIndentAfterType) {
verifyFormat("void\n"
verifyFormat("double\n"
"f();",
getLLVMStyleWithColumns(8));
}