[PATCH] [clang-format] AllowSimpleBracedStatements

Daniel Jasper djasper at google.com
Tue May 13 22:49:36 PDT 2014


It looks like you might have attached the wrong diff. It contains nothing
but formatting changes as far as I can tell.

Cheers,
Daniel


On Mon, May 12, 2014 at 8:19 PM, Gonzalo BG <gonzalobg88 at gmail.com> wrote:

> This patch adds a new option "AllowSimpleBracedStatements" that allows
> braced statements to be considered as "simple". That is, if
> AllowShortIfStatementsOnASingleLine and AllowShortLoopStatementsOnASingle
> line are enabled, code like:
>
> if (true) {
>   f();
> }
>
> can be wrapped into a single line as:
>
> if (true) { f(); }
>
> AllowSimpleBracedStatements defaults to false, meaning that the above
> transformation will not happen since braced block are considered "complex"
> and thus are not allowed to be put on a single line.
>
> This is a fix for http://llvm.org/bugs/show_bug.cgi?id=19193 . There, the
> following remarks were made:
>
> Things to do before this can get accepted:
>> - You clang-format in LLVM style to format the changes (or e.g.
>> git-clang-format).
>> - Add tests, i.e. your test program should be put as unit tests into
>> unittests/Format/FormatTest.cpp
>
>
> These issues have been addressed (hopefully!) in the attached patch
> and adding the tests has made the patch better (so thanks for the
> feedback!).
>
> Some newbie impressions on the clang-format code for those interested:
>
> I have almost no experience with clang-format but after hacking on it a
> bit I feel that in the future there should be a way to format blocks
> independently of them being braced or not, belonging to a function, a
> control statements, a loop, ... Right now there are multiple functions
> dealing with the formatting of blocks and it felt a bit messy.
>
> It also took me a bit to figure out how to add a new test, and how to
> launch clang-format tests only (independently of all others llvm tests) but
> this could probably fixed with a small paragraph in the docs.
>
> Otherwise the code is self explanatory and well documented, and for
> someone like me who has no idea what he is doing (and what clang-format is
> doing) it was really easy to get clang-format to do what I wanted.
>
> Bests,
> Gonzalo BG
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140514/526de165/attachment.html>


More information about the cfe-commits mailing list