]> granicus.if.org Git - clang/commitdiff
This change fixes the formatting of statements such as catch (E& e).
authorManuel Klimek <klimek@google.com>
Mon, 12 Aug 2013 03:51:17 +0000 (03:51 +0000)
committerManuel Klimek <klimek@google.com>
Mon, 12 Aug 2013 03:51:17 +0000 (03:51 +0000)
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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 4af23b01c2f8976a41008af03e77d544117738fa..1a9012fa88dd2ec9ac11b5ab0090306560afee99 100644 (file)
@@ -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;
index 2969e568ebc618b73ab23f243ab1284939bc9900..739c0e5ad94295f0805a052283c99dfc31c1726c 100644 (file)
@@ -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)");