[PATCH] D50078: clang-format: support aligned nested conditionals formatting

Francois Ferrand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 1 07:22:30 PDT 2018


Typz added a comment.

In https://reviews.llvm.org/D50078#1184159, @krasimir wrote:

> Could you clarify how each piece is supposed to be aligned in these examples?
>  This is what makes me happy:
>
>   // column  limit             V
>   int a = condition1 ? result1
>         : conditio2 ? result2
>         : loooooooooocondition 
>           ? result2
>           : dition3 ? resul3
>                     : resul4;
>
>
>
>
>   // column  limit             V
>   int a = condition1 
>           ? loooooresult1
>           : conditio2 ? result2
>                       : result4;
>


It gives the following:

  // column  limit             V
  int a = condition1 ? result1
        : conditio2 ? result2
        : loooooooooocondition
            ? result2
        : dition3 ? resul3
                  : resul4;
  
  // column  limit             V
  int a = condition1
            ? loooooresult1
        : conditio2 ? result2
                    : result4;

i.e. the long result is wrapped and gets an extra indentation.
I have tried quite a bit to "fall back" to the old behavior when there is this kind of wrapping, but this always created other situations which got brocken because of this: so finally I choose to stay consistent, and apply the same behavior whenever there are chained conditionals.

> When BreakBeforeTernaryOperators is false:
> 
>   int a = condition1 ? result1 :
>           conditio2 ? result2 :
>           ditino3 ? resul3 :
>                     result4;

This ones is indeed aligned like this.


Repository:
  rC Clang

https://reviews.llvm.org/D50078





More information about the cfe-commits mailing list