From: Manuel Klimek Date: Mon, 12 Aug 2013 03:51:17 +0000 (+0000) Subject: This change fixes the formatting of statements such as catch (E& e). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2530fd5a235c1e57f8ebef2eae9b365042501009;p=clang This change fixes the formatting of statements such as catch (E& e). Previously these were formatting as catch (E & e) because the inner parenthesis was being marked as an expression. Patch by Thomas Gibson-Robinson. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188153 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 4af23b01c2..1a9012fa88 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -592,7 +592,8 @@ private: } else if (Current.isOneOf(tok::kw_return, tok::kw_throw) || (Current.is(tok::l_paren) && !Line.MustBeDeclaration && !Line.InPPDirective && - (!Current.Previous || Current.Previous->isNot(tok::kw_for)))) { + (!Current.Previous || + !Current.Previous->isOneOf(tok::kw_for, tok::kw_catch)))) { Contexts.back().IsExpression = true; } else if (Current.isOneOf(tok::r_paren, tok::greater, tok::comma)) { for (FormatToken *Previous = Current.Previous; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 2969e568eb..739c0e5ad9 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5563,6 +5563,16 @@ TEST_F(FormatTest, AllmanBraceBreaking) { BreakBeforeBraceShortIfs); } +TEST_F(FormatTest, CatchExceptionReferenceBinding) { + verifyFormat("void f() {\n" + " try {\n" + " }\n" + " catch (const Exception &e) {\n" + " }\n" + "}\n", + getLLVMStyle()); +} + TEST_F(FormatTest, UnderstandsPragmas) { verifyFormat("#pragma omp reduction(| : var)"); verifyFormat("#pragma omp reduction(+ : var)");