[PATCH] [clang-format] add AfterMultilineControlStatement

Rinat Ibragimov via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 6 17:04:17 PDT 2016


Hi.

When indent is four spaces, "if" conditions spanning multiple lines
could be difficult to discern from the "if" body. Indentation is the
same, so they are visually blending. (See example below). One of the
solutions is to place opening brace on a separate line when "if"
condition spans multiple lines. Always putting it on a separate line
in undesired, as there are usually no so many "if"s with multiline
conditions.

To make that possible, proposed patch adds another setting,
BraceWrapping.AfterMultilineControlStatement which acts like
BraceWrapping.AfterControlStatement, but only if condition in control
statement spans over multiple lines.

I didn't see a way to detach brace and move it to the next line once
unwrapped lines are constructed. So when AfterMultilineControlStatement
is enabled, all opening braces go to a separate unwrapped line. Then,
if length of the line is not higher that column limit, code tries
to reattach brace back.

To make what I said above a bit clearer, here are examples:

if (0 + 1 + 2 + 3 + 4 + 5 +
    6 + 7 + 8 + 9 + 10 + 11 +
    12 + 13 + 14 + 15) {
    some_code();
    some_other_code();
}

This patch allows to change that to:

if (0 + 1 + 2 + 3 + 4 + 5 +
    6 + 7 + 8 + 9 + 10 + 11 +
    12 + 13 + 14 + 15)
{
    some_code();
    some_other_code();
}

while keeping opening brace for short conditions on the same line:

if (0) {
    some_code();
}


---
Rinat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-format-introduce-AfterMultilineControlStatement.patch
Type: application/x-patch
Size: 13365 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160807/2263336b/attachment-0001.bin>


More information about the cfe-commits mailing list