[PATCH] D19069: clang-format: Fixed various brace wrapping and block merging bugs

Maxime Beaulieu via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 13 12:17:06 PDT 2016


mxbOctasic added inline comments.

================
Comment at: lib/Format/UnwrappedLineParser.cpp:789-790
@@ -773,4 +788,4 @@
       if (FormatTok->Tok.is(tok::l_brace)) {
-        if (Style.BraceWrapping.AfterObjCDeclaration)
-          addUnwrappedLine();
+        CompoundStatementIndenter Indenter(
+            this, Style, Line->Level, Style.BraceWrapping.AfterObjCDeclaration);
         parseBlock(/*MustBeDeclaration=*/false);
----------------
We may not want this.

================
Comment at: lib/Format/UnwrappedLineParser.cpp:1388-1390
@@ -1372,3 +1387,5 @@
     parseBlock(/*MustBeDeclaration=*/false);
-    if (Style.BraceWrapping.BeforeElse)
+    if (Style.BraceWrapping.BeforeElse ||
+        Style.BraceWrapping.AfterControlStatement &&
+            Style.BraceWrapping.IndentBraces)
       addUnwrappedLine();
----------------
IndentBraces can only work properly when both AfterControlStatement and BeforeElse are active.
The opening brace can only be indented when it is wrapped on its own line, and the else keyword has to be on another line too.
We have to decide which option has precedence over the others.
Right now I'm overriding BeforeElse when the opening brace is wrapped.

================
Comment at: unittests/Format/FormatTest.cpp:2454-2456
@@ -2340,3 +2453,5 @@
   // Function-level try statements.
-  verifyFormat("int f() try { return 4; } catch (...) {\n"
+  verifyFormat("int f() try {\n"
+               "  return 4;\n"
+               "} catch (...) {\n"
                "  return 5;\n"
----------------
This test probably should not have been changed.
However, it's strange to have the try on one line but not the catch.


http://reviews.llvm.org/D19069





More information about the cfe-commits mailing list