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

Francois Ferrand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 31 09:49:01 PDT 2018

Typz added a comment.


- I choose not to add an option to enable this behavior, as I think of it as just another way clang-format can (better) format the code; but I can one if needed
- Currently, it relies on another patch (https://reviews.llvm.org/D32478), which supports aligning the wrapped operator slightly differently. If/since that other patch does not seem to make it, I can change this patch to either do the alignment in this specific case (e.g. for wrapped ternary operator only) or to keep the 'default' behavior of clang-format (e.g. the wrapped colon would be aligned with the first condition):

  // i.e. the better looking option, but which requires specific cases when it comes after assignment or return:
  int fooo = aaaa ? 00000
           : bbbb ? 11111
                  : 2222;
  // or the option more consistent with current clang-format behavior:
  int fooo = aaaa   ? 00000
             : bbbb ? 11111
                    : 2222;

The current patch supports both behaviors, as it relies on https://reviews.llvm.org/D32478 to specify the expected behavior.

  rC Clang


More information about the cfe-commits mailing list