Why are the breaks sometimes removed when AlwaysBreakAfterReturnType is All?

Hi

I’m trying to understand this clang-format behaviour.

When AlwaysBreakAfterReturnType is set to All the break after the return type is removed in some cases.

For example:

printf "int\nshort();\n" | clang-format -style='{ AlwaysBreakAfterReturnType: All }'

returns

int short();

instead of

int
short();

Is there some other option that also affects the break?

Thanks
Matt

This is because short is a keyword. Try e.g. int abcde();. If you still run into problems, you can file an issue on GitHub.

1 Like

Ah, silly of me to use “short” as my test case.

This is closer to my actual code:

printf "int\niso_time(time_t);\n" | clang-format -style='{ AlwaysBreakAfterReturnType: All }'

returning

int iso_time(time_t);

Am I missing something else about keywords in this case? It works if make the arg a “time_t *”.

Thanks for the help.

1 Like

clang-format should be able to handle this if it knows that time_t is a type name. I’ve opened a pull request that will fix this, provided that you add time_t to the TypeNames option:

$ printf "int\niso_time(time_t);\n" | clang-format -style='{ AlwaysBreakAfterReturnType: All, TypeNames: [time_t] }'
int
iso_time(time_t);
$