i have a very strange behavior with my current .clang-format
file.
here is the file:
---
BasedOnStyle: LLVM
ColumnLimit: 200
IndentWidth: 4
UseTab: Always
TabWidth: 4
BreakBeforeBraces: Linux
considering this example C code it will format it as expected:
struct foo {
char a;
int b;
};
static const struct foo data[] = {
{'a', 1},
{'b', 2},
{'c', 3},
};
however if i add an empty {}
element in my array, clang-format will put the complete array initialization in one line:
struct foo {
char a;
int b;
};
static const struct foo data[] = {{'a', 1}, {'b', 2}, {'c', 3}, {}};
is there a way to tell clang-format
to allow an empty element in a line and to correctly format the code as in the first example?
EDIT1:
as Nullndr suggested adding a traling ,
will get clang-format to create the right formatting.
however lets rephrase the question: is there a way to tell clang-format to do the formatting correct even without trailing ,
?
EDIT2: it seems this is a bug in clang-format. i reported it here: https://github.com/llvm/llvm-project/issues/61585