Open brevzin opened 1 year ago
@llvm/issue-subscribers-clang-format
This appears to be an interaction between the continuation indent and regular indents, which is perhaps better observed by using an IndentWidth smaller than the ContinuationIndentWidth, such as default LLVM:
struct C {
auto format(X const &x, auto &ctx const) {
auto some_very_long_name =
[&]() -> Optional<abcd::SufficientlyLongName const &> {
if (true) {
return {};
} else {
return {};
}
};
return 42;
}
};
The lambda is broken to the next line as a continuation, but the contents of it act as if the lambda was never broken to a continuation line.
I'm not familiar with clang-format indentation logic, but poking around a bit, it seems this isn't easy to patch because scopes are indented almost independently of each other. This property manifests with anything that introduces a new scope, such as this if case:
auto f() {
if (a_long_name_for_something + another_long_name ==
stuff_stuff_stuff) {
operation();
// | ^ odd gap going left
}
};
It's just a lot more noticeable on lambdas but I do agree it looks like an issue (just one that I don't know how to fix)
Perhaps as a workaround you could increase the ContinuationIndentWidth in your config?
My
.clang-format
looks like this:which produces this indendation:
The body of the lambda should be indented with respect to the signature of the lambda, that doesn't happen in this case - which looks weird and there doesn't seem to be any option to fix it. The desired indentation would be:
With the
};
of the lambda also indented.