I'm running clang-format
, with a .clang-format
file which only specifies Language: Cpp
, on this input (invalid C++, but that's unimportant for this):
const auto SOME_VARIABLE_NAME = {{"key", { {"key2", std::array{ 0, 0, 0, 0, }}, }}};
I get this output:
const auto SOME_VARIABLE_NAME = {{"key",
{
{"key2",
std::array{
0,
0,
0,
0,
}},
}}};
I would something closer to the following output:
const auto SOME_VARIABLE_NAME = {{"key",
{
{"key2",
std::array{0, 0, 0, 0}},
}}};
I am not sure why clang-format puts a line break after each 0
, around column 50.
What setting should I add to my .clang-format
to achieve this?
I've tried a few specifiers that I thought might be relevant, to no avail:
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: true
BinPackParameters: true
BreakBeforeBinaryOperators: false
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: false
IndentFunctionDeclarationAfterType: true
PenaltyBreakBeforeFirstCallParameter: 1000
Standard: Cpp11
Edit: Still have this problem. Added a comment after the first brace to at least force the braces to the left more:
const auto SOME_VARIABLE_NAME = { //
{"key",
{
{"key2",
std::array{
0,
0,
0,
0,
}},
}}};
The issue is with the trailing comma immediately before the closing brace. The trailing comma (which is optional in c++
) tells clang-format
to put each element on a separate line. I don't know where this convention comes from, and it does not seem to be documented. In your case, it seems to be getting in the way.
If you remove just the comma after the last "0", the default clang-format
settings produce this:
const auto SOME_VARIABLE_NAME = {{"key",
{
{"key2", std::array{0, 0, 0, 0}},
}}};
...which is not quite what you were asking for, but is fairly close.
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras