r220686 - clang-format: Don't break after very short return types.
Daniel Jasper
djasper at google.com
Mon Oct 27 10:13:59 PDT 2014
Author: djasper
Date: Mon Oct 27 12:13:59 2014
New Revision: 220686
URL: http://llvm.org/viewvc/llvm-project?rev=220686&view=rev
Log:
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).
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=220686&r1=220685&r2=220686&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Oct 27 12:13:59 2014
@@ -122,6 +122,12 @@ bool ContinuationIndenter::canBreak(cons
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;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=220686&r1=220685&r2=220686&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Oct 27 12:13:59 2014
@@ -1207,8 +1207,8 @@ TEST_F(FormatTest, CorrectlyHandlesLengt
}
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, BreaksFunctionDeclara
// 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, ConfigurableIndentWid
}
TEST_F(FormatTest, ConfigurableFunctionDeclarationIndentAfterType) {
- verifyFormat("void\n"
+ verifyFormat("double\n"
"f();",
getLLVMStyleWithColumns(8));
}
More information about the cfe-commits
mailing list