2

I'm using clang-format (through VScode) and it's refactoring my array definition code this way

int my_array[] = { OPTION1, 2, OPTION2, 4, END}; 

while I would like the ending braces to go to the next line

int my_array[] = { OPTION1, 2, OPTION2, 4, END }; 

I can't seem to find the right setting. Any idea how could I get this?

2
  • Can you show your current .clang-format file? Commented Nov 14, 2019 at 15:09
  • also I'm not sure what you want is possible with clang format Commented Nov 14, 2019 at 15:55

3 Answers 3

2

Two options:

  1. Cpp11BracedListStyle: false disables moving the closing brace

  2. Add a trailing comma to the last element of the array:

int my_array[] = { OPTION1, 2, OPTION2, 4, END, }; 
Sign up to request clarification or add additional context in comments.

Comments

1

Adding a comment also works:

int my_array[] = { OPTION1, 2, OPTION2, 4, END // last element }; 

Comments

0

It can be done by adding // clang-format off

// clang-format off int my_array[] = { OPTION1, 2, OPTION2, 4, END }; // clang-format on 

However it is not the most elegant solution.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.