llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.03k stars 11.58k forks source link

[clang-format]: nested array of structures alignment #55483

Open igagis opened 2 years ago

igagis commented 2 years ago

input

.clang-format:

---
AlignArrayOfStructures: Right
ColumnLimit: '120'
ContinuationIndentWidth: '1'
IndentWidth: '1'
Language: Cpp
Standard: Latest
TabWidth: '1'
UseCRLF: 'false'
UseTab: ForContinuationAndIndentation

...

main.cpp:

type expected = {
    { 
        "1",
        {
            {"1",  1, 2},
            {"1", 11, 6}
        }
    },
    {
        "13",
        {
            {"13",  13, 0},
            {"13", 132, 3},
            {"13", 133, 5}
        }
    },
    {
        "14",
        {
            {"14", 14, 1}
        }
    },
    {
        "15",
        {
            {"15", 15, 4}
        }
    }
};

result after formatting

type expected = {
    { "1",                                                                                  {{"1", 1, 2}, {"1", 11, 6}}},
    {"13", {{"13", 13, 0}, {"13", 132, 3}, {"13", 133, 5}}},
    {"14",                                                                                                                  {{"14", 14, 1}}},
    {"15",                                                                                                                  {{"15", 15, 4}}}
};

The formatted result makes no sense.

proposal

Proposal is to format nested array of structures as in input file above. I.e. if an array has another array as one of it's elements, then this array is formatted as one element per line.

version

$ clang-format --version
Debian clang-format version 15.0.0-++20220513071846+693758b28295-1~exp1~20220513071937.249
llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-format

david-drinn commented 1 year ago

Another perhaps more general case, is that a two+ dimensional array of standard type variables, such as int or float, doesn't follow the alignment setting.