Skip to content

[clang-format] Misaligned trailing comment on default case with AlignConsecutiveShortCaseStatements #161973

@Alunderin

Description

@Alunderin

With this config:

AllowShortCaseLabelsOnASingleLine: true
AlignConsecutiveShortCaseStatements:
  Enabled: true

Trailing comments on "short default statements" are misaligned if other trailing comments are present.
For this to occur at least one case label has to be longer than the default label.

switch (state) {
case State::Idle:    return 1; // Aligned
case State::Running: return 2; // Aligned
default:             return 3;             // Oops!
};

Interestingly, the alignment is only affected by the length of the case label, not the whole statement.

Tested with version 18.1.3 (Ubuntu) and 22.0.0git (commit 3c39187)

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