Skip to content

clang-format poor spacing with braces initializer #62904

@cmcqueen

Description

@cmcqueen

test.c containing:

static const CMD_HANDLER_T command_handlers[] =
{
    {   "a",            HandleA             },
    {   "bb",           HandleBB            },
    {   "ccc",          HandleCCC           },
    {   NULL,           NULL                },
};

Command:

clang-format -style="{ SpacesInParentheses: true, AlignArrayOfStructures: Left }" test.c > test.out.c

Result:

static const CMD_HANDLER_T command_handlers[] = {
    {"a",    HandleA  },
    { "bb",  HandleBB },
    { "ccc", HandleCCC},
    { NULL,  NULL     },
};

Anomalous things:

  • For the first row only, there is no space between the opening brace and the first value.
  • For the row with the widest last value, there is no space between the last value and the closing brace.

I have tested this with Clang-Format v13.0.1, v15.0.7 and v16.0.0, with the same results.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions