llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-format] Cannot disable array initializer bin packing

Open JonnyHaystack opened this issue 3 years ago • 2 comments

See https://reviews.llvm.org/D38636

This is still an issue, and the behaviour is quite inconsistent. When using AlignArrayOfStructures: Left or AlignArrayOfStructures: Right, it does put them each on one line, but using AlignArrayOfStructures: None results in the nested initializers being bin packed despite the fact that I have BinPackArguments: false and BinPackParameters: false.

It's also import to note that it ignores the usual behaviour where using a trailing comma in an array initializer should disable bin packing.

Would be nice to have this consistent with the behaviour of AlignAfterOpenBracket: BlockIndent (which works perfectly) as well.

With AlignArrayOfStructures: None:

things_t array_of_things[] = {
    { true, false }, { false, true }, { true, false },
    { false, true }, { true, false }, { false, true },
};

I don't want bin packing at all so this is no good.

With AlignArrayOfStructures: Left:

things_t array_of_things[] = {
    {true,   false},
    { false, true },
    { true,  false},
    { false, true },
    { true,  false},
    { false, true },
};

This is closer to what I want, but I'd prefer to be able to do this without having to align the columns. Also the top left cell is always misaligned for some reason, which is rather annoying.

With AlignArrayOfStructures: Right:

things_t array_of_things[] = {
    { true, false},
    {false,  true},
    { true, false},
    {false,  true},
    { true, false},
    {false,  true},
};

As above, but at least this doesn't have that problem with one of the cells being misaligned.

JonnyHaystack avatar Apr 28 '22 20:04 JonnyHaystack

@llvm/issue-subscribers-clang-format

llvmbot avatar Apr 28 '22 21:04 llvmbot

How to just stop disable bin packing? I want to keep line breaks even the line not exceed the max length.

BinPackArguments: false
BinPackParameters: false

Won't be helpful.

scruel avatar Oct 17 '22 10:10 scruel

How to just stop disable bin packing? I want to keep line breaks even the line not exceed the max length.

BinPackArguments: false
BinPackParameters: false

Won't be helpful.

yea I want to be able to align my arguments in a function anyway i want and this thing forces me to either have them to be on either one line/packed if over the column limit or one in each line.

Did you find a way to get over this limitation??

EDIT: Got a fix. Set both to true and then set column limit to 0. Works like charm. Setting it to zero is making it accept the break inserted by the user since there is no defined column limit

Ashwini6516 avatar Mar 05 '24 06:03 Ashwini6516