[PATCH] D15485: [clang-format] BraceWrapping.BeforeElse is incorrect for BS_Linux

Kent Sutherland via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 13 19:47:22 PST 2015


ksuther created this revision.
ksuther added reviewers: cfe-commits, djasper.
Herald added a subscriber: klimek.

The BraceWrapping of the Linux style is incorrect. This appeared in r248802 when the custom BraceWrapping options were added.

This is what r248801 looked like:

clang-format -style="{BasedOnStyle: google,  BreakBeforeBraces: Linux}" ~/Desktop/format.m 
void main()
{
  if (blah) {
    stuff();
  } else {
    more();
  }
}

This is what r248802 (and trunk) looks like:

clang-format -style="{BasedOnStyle: google,  BreakBeforeBraces: Linux}" ~/Desktop/format.m 
void main()
{
  if (blah) {
    stuff();
  }
  else {
    more();
  }
}

The behavior before r248802 is correct based on the documentation:

BS_Linux (in configuration: Linux) Like Attach, but break before braces on function, namespace and class definitions.

I changed BraceWrapping.BeforeElse to false for Linux and added and else statement to the Linux brace test.

http://reviews.llvm.org/D15485

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9003,6 +9003,8 @@
                "    if (true) {\n"
                "      a();\n"
                "      b();\n"
+               "    } else {\n"
+               "      c();\n"
                "    }\n"
                "  }\n"
                "  void g() { return; }\n"
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -396,7 +396,7 @@
     Expanded.BraceWrapping.AfterClass = true;
     Expanded.BraceWrapping.AfterFunction = true;
     Expanded.BraceWrapping.AfterNamespace = true;
-    Expanded.BraceWrapping.BeforeElse = true;
+    Expanded.BraceWrapping.BeforeElse = false;
     break;
   case FormatStyle::BS_Mozilla:
     Expanded.BraceWrapping.AfterClass = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15485.42680.patch
Type: text/x-patch
Size: 960 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151214/9f017a55/attachment.bin>


More information about the cfe-commits mailing list