From: Owen Pan Date: Fri, 28 Sep 2018 09:17:00 +0000 (+0000) Subject: [ClangFormat] 'try' of function-try-block doesn't obey BraceWrapping X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=784cbe17cab0ca6cda9a24d094292fd97992019c;p=clang [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 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 752357c1af..09cd660e6d 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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: { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index dac8497c1e..3e23c5e11b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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"