Re: [PATCH] [clang-format] add AfterMultilineControlStatement

Rinat Ibragimov via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 7 13:05:17 PDT 2016


I've seen couple of projects that have similar opening brace placement
for multiline conditions. Here are links to their style guides:

https://github.com/mpv-player/mpv/blob/master/DOCS/contribute.md

and

http://gem5.org/Coding_Style#Braces


>Воскресенье,  7 августа 2016, 3:04 +03:00 от Rinat Ibragimov via cfe-commits <cfe-commits at lists.llvm.org>:
>
>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
>_______________________________________________
>cfe-commits mailing list
>cfe-commits at lists.llvm.org
>http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


---
Rinat


More information about the cfe-commits mailing list