[C/C++][clang-format] Exempt Specific Function-Like Symbols From The One-Line Rule

Dear Clang Community,

TL:DR; If at all possible, how can I wrangle clang-format to give me:

  1. The following as one line

ierr = FunctionCall();CHKERRQ(ierr);

And not

ierr = FunctionCall();

  1. Function parameters without spaces:


And not

FunctionCall(a, b, c);

No holds barred here, modifying clang-format internals/providing patches is not off the table.


For 1. it’s hard to tell when you want to merge these (logical) lines into a single physical one.
Anyway, it can be done in two ways in clang-format (or a mix of the two).
Either, by not adding an unwrapped line when parsing a semicolon (e.g. in places like this: llvm-project/UnwrappedLineParser.cpp at e01f624adb0ed5d0f1369b0679a64484bac10d02 · llvm/llvm-project (github.com)).
Or, by merging lines afterwards (cf. LineJoiner llvm-project/UnwrappedLineFormatter.cpp at e01f624adb0ed5d0f1369b0679a64484bac10d02 · llvm/llvm-project (github.com)).
The condition in which these should be done depends on your use case.
Anyway, it seems non-trivial to me.

For 2. it should be pretty simple (with a new option though) that will not require a space after a comma:
Cf. llvm-project/TokenAnnotator.cpp at e01f624adb0ed5d0f1369b0679a64484bac10d02 · llvm/llvm-project (github.com)
It may be tricky though to handle only commas inside function calls, because unless I’m mistaken, they’re not annotated as TT_FunctionCallComma or anything alike. If you want to distinguish function calls and function signatures, then there should be a distinction too.

Hope this helps