Why does clang-format add excessive indentation or line breaks to function arguments like std::move(widget) in complex lambdas? How can I configure it to keep arguments inline or reduce unnecessary breaks?
void overlay::remove(std::variant<std::shared_ptr<widget>, std::shared_ptr<label>> &&widget) noexcept {
std::visit([this](auto &&arg) {
std::erase_if(_widgets, [&arg](const auto &existing) {
return existing == arg;
});
},
std::move(widget)); // This line has a excessive amount of identation
}
My .clang-format
BasedOnStyle: LLVM
Language: Cpp
UseTab: Never
BreakBeforeBraces: Attach
AllowShortIfStatementsOnASingleLine: true
IndentCaseLabels: false
ColumnLimit: 0
IndentWidth: 2
TabWidth: 2
AlignAfterOpenBracket: BlockIndent
DerivePointerAlignment: False
PointerAlignment: Right
AccessModifierOffset: -2
QualifierAlignment: Left
FixNamespaceComments: False
AllowShortFunctionsOnASingleLine: Inline
BinPackArguments: true
BinPackParameters: true
How to reduce the indentation?
I have had this same problem, and could never get it to work. However, I found a bug report on this on GitHub: https://github.com/llvm/llvm-project/issues/56283.
It looks like this was never fixed, but there is more info here: https://reviews.llvm.org/D129443
(Took answer from another ans: https://stackoverflow.com/a/74109314/16529532) If it's applicable, I would avoid clang format and use your code editors formatter tool. If you can't that's okay.