forked from OSchip/llvm-project
clang-format: Prefer column layout if possible.
Add a severe penalty for not using column layout for braced lists. If there are solutions with column layout, these are generally preferable over bin-packed solutions. Before: std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa, aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a, aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa, aaaaaaa, a }; After: std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa, aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a, aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa, aaaaaaa, a }; llvm-svn: 195546
This commit is contained in:
parent
556f03ef90
commit
1a1a2ab77e
|
@ -48,8 +48,11 @@ unsigned CommaSeparatedList::format(LineState &State,
|
||||||
|
|
||||||
// Find the best ColumnFormat, i.e. the best number of columns to use.
|
// Find the best ColumnFormat, i.e. the best number of columns to use.
|
||||||
const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
|
const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
|
||||||
|
// If no ColumnFormat can be used, the braced list would generally be
|
||||||
|
// bin-packed. Add a severe penalty to this so that column layouts are
|
||||||
|
// prefered if possible.
|
||||||
if (!Format)
|
if (!Format)
|
||||||
return 0;
|
return 10000;
|
||||||
|
|
||||||
// Format the entire list.
|
// Format the entire list.
|
||||||
unsigned Penalty = 0;
|
unsigned Penalty = 0;
|
||||||
|
|
|
@ -4698,6 +4698,14 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
|
||||||
verifyFormat(
|
verifyFormat(
|
||||||
"std::this_thread::sleep_for(\n"
|
"std::this_thread::sleep_for(\n"
|
||||||
" std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5);");
|
" std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5);");
|
||||||
|
verifyFormat("std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{\n"
|
||||||
|
" aaaaaaa, aaaaaaaaaa,\n"
|
||||||
|
" aaaaa, aaaaaaaaaaaaaaa,\n"
|
||||||
|
" aaa, aaaaaaaaaa,\n"
|
||||||
|
" a, aaaaaaaaaaaaaaaaaaaaa,\n"
|
||||||
|
" aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa,\n"
|
||||||
|
" aaaaaaa, a\n"
|
||||||
|
"};");
|
||||||
|
|
||||||
FormatStyle NoSpaces = getLLVMStyle();
|
FormatStyle NoSpaces = getLLVMStyle();
|
||||||
NoSpaces.Cpp11BracedListStyle = true;
|
NoSpaces.Cpp11BracedListStyle = true;
|
||||||
|
|
Loading…
Reference in New Issue