r249519 - Make clang-format actually respect custom brace wrapping flags.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 6 21:06:11 PDT 2015


Author: djasper
Date: Tue Oct  6 23:06:10 2015
New Revision: 249519

URL: http://llvm.org/viewvc/llvm-project?rev=249519&view=rev
Log:
Make clang-format actually respect custom brace wrapping flags.

This fixes llvm.org/PR25073.

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=249519&r1=249518&r2=249519&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Oct  6 23:06:10 2015
@@ -372,6 +372,8 @@ std::string ParseErrorCategory::message(
 }
 
 static FormatStyle expandPresets(const FormatStyle &Style) {
+  if (Style.BreakBeforeBraces == FormatStyle::BS_Custom)
+    return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
                             false, false, false, false, false};
@@ -442,6 +444,8 @@ FormatStyle getLLVMStyle() {
   LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
   LLVMStyle.BreakBeforeTernaryOperators = true;
   LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
+  LLVMStyle.BraceWrapping = {false, false, false, false, false, false,
+                             false, false, false, false, false};
   LLVMStyle.BreakConstructorInitializersBeforeComma = false;
   LLVMStyle.ColumnLimit = 80;
   LLVMStyle.CommentPragmas = "^ IWYU pragma:";

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=249519&r1=249518&r2=249519&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Oct  6 23:06:10 2015
@@ -2332,8 +2332,8 @@ TEST_F(FormatTest, IncompleteTryCatchBlo
 
 TEST_F(FormatTest, FormatTryCatchBraceStyles) {
   FormatStyle Style = getLLVMStyle();
-  for (auto BraceStyle :
-       {FormatStyle::BS_Attach, FormatStyle::BS_Mozilla, FormatStyle::BS_WebKit}) {
+  for (auto BraceStyle : {FormatStyle::BS_Attach, FormatStyle::BS_Mozilla,
+                          FormatStyle::BS_WebKit}) {
     Style.BreakBeforeBraces = BraceStyle;
     verifyFormat("try {\n"
                  "  // something\n"
@@ -2384,6 +2384,15 @@ TEST_F(FormatTest, FormatTryCatchBraceSt
                "    // something\n"
                "  }",
                Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.BeforeCatch = true;
+  verifyFormat("try {\n"
+               "  // something\n"
+               "}\n"
+               "catch (...) {\n"
+               "  // something\n"
+               "}",
+               Style);
 }
 
 TEST_F(FormatTest, FormatObjCTryCatch) {




More information about the cfe-commits mailing list