We had some code that looked like this:
int foo() { #pragma region hello(foo) #pragma endregion } foo* bar() {}
This was confusingly indented like:
int foo() { #pragma region... }
After some investigation I noticed that this is because
parseBracedList() thought that this was a initializer list.
The check here: https://github.com/tru/llvm-project/blob/main/clang/lib/Format/UnwrappedLineParser.cpp#L709
will mark the code above as ProbablyBracedList and then it
will format it totally wrong depending on your style settings.
My initial fix was to change the check above, but it became
really complicated to keep both initializer lists and my code
working.
My approach here instead is to discard any line that starts with #
since that is a pre-processor statement we shouldn't really care
about it in this case.
This fix passes all the unittests and our internal code-base, so
I am fairly confident in it, but I am no clang-format expert.
Can you clean up the tests a little? i.e. use verifyFormat() and have one string literal per test case line?