Skip to content

clang-format poor comment spacing with AlignArrayOfStructures #69342

@kadler

Description

@kadler

Similar to #62904 I've also noticed weird alignment issues of comments inside array initializers when AlignArrayOfStructures is enabled:

test.c

struct point {
    int x, y;
}

struct point points[] = {
    // test of single line comment
    {0, 1},
    /* this is a C-style comment */
    {1, 2},
            // overly indented comment
    {3, 4},
        /* overly indented C-style comment */
    {0, 0}
};
clang-format -style="{ ContinuationIndentWidth: 8, AlignArrayOfStructures: Left }" test.c
struct point {
  int x, y;
}

struct point points[] = {
  // test of single line comment
        {0, 1},
 /* this is a C-style comment */
        {1, 2},
 // overly indented comment
        {3, 4},
 /* overly indented C-style comment */
        {0, 0}
};
clang-format -style="{ ContinuationIndentWidth: 8, AlignArrayOfStructures: Right }" test.c
struct point {
  int x, y;
}

struct point points[] = {
  // test of single line comment
        {0, 1},
 /* this is a C-style comment */
        {1, 2},
 // overly indented comment
        {3, 4},
 /* overly indented C-style comment */
        {0, 0}
};
clang-format -style="{ ContinuationIndentWidth: 8, AlignArrayOfStructures: None }" test.c
struct point {
  int x, y;
}

struct point points[] = {
        // test of single line comment
        {0, 1},
        /* this is a C-style comment */
        {1, 2},
        // overly indented comment
        {3, 4},
        /* overly indented C-style comment */
        {0, 0}};

When Using AlignArrayOfStructures with either Left or Right options, the indentation of the comments does not follow the indentation of the array contents. The first comment is indented two spaces while subsequent comments are indented one space. Neither IndentWidth nor ContinuationindentWidth seem to have any effect on this behavior.

This is with clang-format 16.0.6 from macOS Homebrew.

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