[clang] [clang-format] Fix a bug in annotating function declaration names (PR #76206)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 22 12:14:27 PST 2023


HazardyKnusperkeks wrote:

> Thanks for doing this. Does it mean we would have to add every type we use to our config? It would be much more convenient if clang-format treated the argument list the same way that it treats in definitions. For example
> 
> ```shell
> printf "int\niso_time(time_t) { return 1; }\n" | clang-format -style='{ AlwaysBreakAfterReturnType: All }'
> ```
> 
> gives
> 
> ```c
> int
> iso_time(time_t) {
>   return 1;
> }
> ```
> 
> whereas
> 
> ```shell
> printf "int\niso_time(time_t);\n" | clang-format -style='{ AlwaysBreakAfterReturnType: All }'
> ```
> 
> will need a config edit to work.
> 

`clang-format` doesn't know what are types, except for the keywords. So there is no way to decide if this is a function declaration without naming the parameters, or a variable declaration with a constructor call.

https://github.com/llvm/llvm-project/pull/76206


More information about the cfe-commits mailing list