diff options
author | Owen Pan <owenpiano@gmail.com> | 2018-09-28 09:17:00 +0000 |
---|---|---|
committer | Owen Pan <owenpiano@gmail.com> | 2018-09-28 09:17:00 +0000 |
commit | 3b204378fe5e8fbaae3f8703431c2df2e85134ec (patch) | |
tree | 29805191729e69c1133b9c5b8079a4053870b2b4 | |
parent | 0fa18f04bfe2d9163b7a93f5983aa0f596eae7f9 (diff) |
[ClangFormat] 'try' of function-try-block doesn't obey BraceWrapping
It should respond to AfterFunction, not AfterControlStatement.
Fixes PR39067
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 752357c1aff..09cd660e6de 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index dac8497c1e6..3e23c5e11b5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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" |