In our project, we sometimes initialise arrays on one line, and sometimes we initialise them as blocks. That is
strings::UniChar const s[] = {'H', 'e', 'l', 'l', 'o'}; 
vs
strings::UniChar const s[] = 
{
 'H', 
 'e', 
 'l', 
 'l', 
 'o'
};
I would like to clang-format to be able to distinguish between the two types and not convert the second into the first one or align the elements after the opening brace. That is not like this: 
strings::UniChar const s[] = {'H', 
 'e', 
 'l', 
 'l', 
 'o'};
Is there a way to achieve that using config files?
4 Answers 4
Adding a comma after the last array element causes clang-format (tried with v6.0.0) to align the elements to the left side, like your second example.
// With a trailing comma.
char buf[] = {
 'a',
 'b',
};
// Without a trailing comma.
char buf2[] = {'a', 'b'};
Comments
try "Cpp11BracedListStyle: false"
Comments
You can force a line break with //:
strings::UniChar const s[] = {
 'H', //
 'e', //
 'l', //
 'l', //
 'o' //
};
2 Comments
Cpp11BracedListStyle: false to get the format I wanted for the initializer on a multi-dimensional array.This is an absolutely relevant question, since there's still no way to disable bin packing for array initializers.
The most flexible option is to use comments, as it lets you format arrays into anything, including visually distinct matrices, e.g.:
static constexpr bool shape[] = {
 0, 1, 0, //
 1, 1, 1, //
 0, 1, 1, //
};
Without comments, clang-format will put that array in one line and break on column limit, and there's no way to prevent it by changing the config file.
If you don't care for that and only want 1 column initializations, then the already mentioned Cpp11BracedListStyle: false is enough.
/* clang-format off */