[PATCH] D68296: clang-format: Add ability to wrap braces after multi-line control statements

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 09:48:00 PDT 2019


MyDeveloperDay added a comment.

As I mentioned, its worth getting evidence from a large public project...

https://wiki.blender.org/index.php/Dev:Doc/Code_Style

Blender public repo on github.com has 90 Forks, 299 * and 90,000 commits

>From their style guide

  Exceptions to Braces on Same Line
  When flow control (if, for, while) is broken up into multiple lines, it reads better to have the brace on its own lines.
  
  /* Don't: */
      if ((very_long_function_check(that, has, many, arguments)) &&
          (another_very_long_function(some, more, arguments)) &&
          some_more_checks_this_gets_tedious(but, its, readable)) {
          some_other_check_this_could_be_confusing ? func_a() : func_b();
      }
  
  /* Do: */
      if ((very_long_function_check(that, has, many, arguments)) &&
          (another_very_long_function(some, more, arguments)) &&
          some_more_checks_this_gets_tedious(but, its, readable))
      {
          (some_other_check_this_could_be_confusing && n) ? func_a() : func_b();
      }

https://developer.blender.org/T53211

  # NOTE: At time of writing (10/30/2017) not all formatting can be made exactly
  # like current Blender sources, so a few compromises are made:
  #
  #   1. Newline after : in switch statements: clang-format will put the { on
  #      the same line. This is due to a limitation in clang-format; it does not
  #      support adding the newline after cases in switch statements.
  #   2. Nested preprocessor directives don't get proper indentation after the
  #      '#'. See IndentPPDirectives, which is supported in clang-format from
  #      LLVM6, but not LLVM5. It is included below but commented out.
  #   3. Special case of { position on if statements where the condition covers
  #      more than one line. clang-format is an all or nothing formatter in this
  #      case; so unfortunately the case of
  #
  #      if (long_condition_here() ||
  #          long_condition_here() ||
  #          long_condition_here() ||
  #          long_condition_here())
  #      {
  #          ...
  #      }
  #
  #      will become
  #
  #      if (long_condition_here() ||
  #          long_condition_here() ||
  #          long_condition_here() ||
  #          long_condition_here()) {
  #          ...
  #      }
  #


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68296/new/

https://reviews.llvm.org/D68296





More information about the cfe-commits mailing list