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

Mitchell via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 1 14:02:14 PDT 2019


mitchell-stellar created this revision.
mitchell-stellar added reviewers: sammccall, owenpan, reuk.
mitchell-stellar added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Change the BraceWrappingFlags' AfterControlStatement from a bool to an enum with three values:

- "Never": This is the default, and does not do any brace wrapping after control statements.
- "OnlyMultiLine": This only wraps braces after multi-line control statements (this really only happens when a ColumnLimit is specified).
- "Always": This always wraps braces after control statements.

The first and last options are backwards-compatible with "false" and "true", respectively.

The new "OnlyMultiLine" option is useful for when a wrapped control statement's indentation matches the subsequent block's indentation. It makes it easier to see at a glance where the control statement ends and where the block's code begins. For example:

  if (
    foo
    && bar )
  {
    baz();
  }

vs.

  if (
    foo
    && bar ) {
    baz();
  }


Repository:
  rC Clang

https://reviews.llvm.org/D68296

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestObjC.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68296.222695.patch
Type: text/x-patch
Size: 19704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191001/bc374652/attachment-0001.bin>


More information about the cfe-commits mailing list