[llvm-dev] Change coding style for argument alignment?

Nikita Popov via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 3 13:00:50 PST 2020


LLVM currently uses a coding style where arguments and parameters need to
be aligned to the opening parenthesis "(".

    someFunctionCall(Arg1, Arg2,
                     Arg3, Arg4);

This style guideline is unfortunate for a couple of reasons:

1. If a function is renamed, it is necessary to also reindent the arguments
at all call-sites. For functions with many or complex arguments, this may
require significant reflow.

2. It causes significant right-ward drift. Especially for declarations,
it's somewhat common for code ending up like this...

   Foo SomeClassName::someMethodName(Bar &Arg1,
                                      Bar &Arg2,
                                      Bar &Arg3,
                                      Bar &Arg4) {

... because there is just enough space to fit each argument individually,
but still a need to break each one out on a separate line. Closure
arguments are another common case of very awkward formatting.

3. There are some arcane rules about when this is not the preferred style
and you're supposed to indent arguments on the following line instead.

Is there any chance that the style could be changed towards indenting (but
not aligning) the following line instead?

        Arg1, Arg2, Arg3, Arg4);

This is unaffected by renames, does not cause rightward drift and results
in very predictable formatting.

Based on past discussions, LLVM seems to be open to improving coding style
for the better, so I thought I'd give this a shot, as this is a continuous
source of friction for me.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201203/a1d28c4c/attachment.html>

More information about the llvm-dev mailing list