Skip to content

incorrect indentation with clang-format's AlignConsecutiveAssignments: true #55161

@zmodem

Description

@zmodem

Consider:

$ cat /tmp/a.cc
#if A
bool thisisalongvariablename = true;
#else
bool thisisalongvariablename = false;
#endif

#if B
bool shortervarname = true;
#else
bool shortervarname = false;
#endif

void foo() {
#if C
#else
  if (bar) {
    baz();
  }
#endif
}

$ build.release/bin/clang-format -style="{AlignConsecutiveAssignments: true}" /tmp/a.cc 
#if A
bool thisisalongvariablename = true;
#else
bool thisisalongvariablename = false;
#endif

#if B
bool shortervarname = true;
#else
bool shortervarname          = false;
#endif

void foo() {
#if C
#else
  if (bar) {
             baz();
  }
#endif
}

Note that the second assignment to shortervarname gets aligned, but not the first one.
And the indentation for baz() is wrong.
The issues seem to be connected.

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorclang-format

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions