]> granicus.if.org Git - clang/commitdiff
[ClangFormat] 'try' of function-try-block doesn't obey BraceWrapping
authorOwen Pan <owenpiano@gmail.com>
Fri, 28 Sep 2018 09:17:00 +0000 (09:17 +0000)
committerOwen Pan <owenpiano@gmail.com>
Fri, 28 Sep 2018 09:17:00 +0000 (09:17 +0000)
It should respond to AfterFunction, not AfterControlStatement.

Fixes PR39067

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343305 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 752357c1affb39100e7fae8d77361f678765f882..09cd660e6dee69f4e9e6737992c08a1402128bb2 100644 (file)
@@ -1266,6 +1266,8 @@ void UnwrappedLineParser::parseStructuralElement() {
       break;
     case tok::kw_try:
       // We arrive here when parsing function-try blocks.
+      if (Style.BraceWrapping.AfterFunction)
+        addUnwrappedLine();
       parseTryCatch();
       return;
     case tok::identifier: {
index dac8497c1e6aa9bd1758a776f523dd6ac9f064d2..3e23c5e11b5beedebb5dbc3b486ca43d4faa9e73 100644 (file)
@@ -2628,6 +2628,16 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) {
                    "  A(X x)\n"
                    "  try : t(0) {} catch (...) {}\n"
                    "};"));
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterControlStatement = true;
+  Style.BraceWrapping.AfterFunction = true;
+  EXPECT_EQ("void f()\n"
+            "try\n"
+            "{\n"
+            "}",
+            format("void f() try {\n"
+                   "}", Style));
   EXPECT_EQ("class SomeClass {\n"
             "public:\n"
             "  SomeClass() EXCLUSIVE_LOCK_FUNCTION(mu_);\n"