Skip to content

Chained method calls aligned incorrectly #52854

@yurikhan

Description

@yurikhan
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal

$ clang-format-12 --version
Ubuntu clang-format version 12.0.0-3ubuntu1~20.04.4

.clang-format:

IndentWidth: 4
TabWidth: 4
UseTab: ForContinuationAndIndentation

Observed indentation:

struct Foo {
→   Foo &long_named_self_returning_method();
};

int main() {
→   auto foo = Foo{}
→   →   →   →   ···.long_named_self_returning_method()
→   →   →   →   ···.long_named_self_returning_method()
→   →   →   →   ···.long_named_self_returning_method()
→   →   →   →   ···.long_named_self_returning_method();
}

Specifically, it looks like continuation lines are indented +4 relative to the expression start Foo{}.

Desired indentation:

struct Foo {
→   Foo &long_named_self_returning_method();
};

int main() {
→   auto foo = Foo{}
→   →   .long_named_self_returning_method()
→   →   .long_named_self_returning_method()
→   →   .long_named_self_returning_method()
→   →   .long_named_self_returning_method();
}

i.e. indent continuation lines relative to the start of preceding line.

I especially consider it a bug to emit the sequence <tab><space>. It will break every reader who uses a different tab width.

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