Author: owenpan Date: Fri Sep 28 02:17:00 2018 New Revision: 343305 URL: http://llvm.org/viewvc/llvm-project?rev=343305&view=rev Log: [ClangFormat] 'try' of function-try-block doesn't obey BraceWrapping
It should respond to AfterFunction, not AfterControlStatement. Fixes PR39067 Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=343305&r1=343304&r2=343305&view=diff ============================================================================== --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original) +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Sep 28 02:17:00 2018 @@ -1266,6 +1266,8 @@ void UnwrappedLineParser::parseStructura break; case tok::kw_try: // We arrive here when parsing function-try blocks. + if (Style.BraceWrapping.AfterFunction) + addUnwrappedLine(); parseTryCatch(); return; case tok::identifier: { Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=343305&r1=343304&r2=343305&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Sep 28 02:17:00 2018 @@ -2628,6 +2628,16 @@ TEST_F(FormatTest, MacroCallsWithoutTrai " 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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits