Browse Source

[ClangFormat] 'try' of function-try-block doesn't obey BraceWrapping

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
Owen Pan 7 years ago
parent
commit
784cbe17ca
2 changed files with 12 additions and 0 deletions
  1. 2 0
      lib/Format/UnwrappedLineParser.cpp
  2. 10 0
      unittests/Format/FormatTest.cpp

+ 2 - 0
lib/Format/UnwrappedLineParser.cpp

@@ -1266,6 +1266,8 @@ void UnwrappedLineParser::parseStructuralElement() {
       break;
       break;
     case tok::kw_try:
     case tok::kw_try:
       // We arrive here when parsing function-try blocks.
       // We arrive here when parsing function-try blocks.
+      if (Style.BraceWrapping.AfterFunction)
+        addUnwrappedLine();
       parseTryCatch();
       parseTryCatch();
       return;
       return;
     case tok::identifier: {
     case tok::identifier: {

+ 10 - 0
unittests/Format/FormatTest.cpp

@@ -2628,6 +2628,16 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) {
                    "  A(X x)\n"
                    "  A(X x)\n"
                    "  try : t(0) {} catch (...) {}\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"
   EXPECT_EQ("class SomeClass {\n"
             "public:\n"
             "public:\n"
             "  SomeClass() EXCLUSIVE_LOCK_FUNCTION(mu_);\n"
             "  SomeClass() EXCLUSIVE_LOCK_FUNCTION(mu_);\n"