llvm / llvm-project

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

Designated initializers prevent formatting under certain conditions #62150

Open memreflect opened 1 year ago

memreflect commented 1 year ago

The last line in the following code is not formatted under certain conditions:

typedef struct {
    struct {
        int y1;
        struct {
            int z1, z2;
        } y2;
    } x;
} S;
S s = { .x = { 0, { 0, 0, }, }, };

I was looking for output similar to this (typedef omitted):

S s = {
    .x = {
        0,
        {
            0,
            0,
        },
    },
};

Adding designated initializers for all relevant fields only creates more visual noise, and removing all designated initializers results in the expected formatting aside from the lack of designated initializers.

I have narrowed the issue down to the following style options (pseudocode) in all currently predefined styles:

if (!ColumnLimit) {
  // formatted
} else if (!Cpp11BracedListStyle) {
  // not formatted
} else if (BreakBeforeBinaryOperators == "All") {
  // not formatted
} else {
  // formatted
}
llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-format