Hi,

the issue here is that we don't diagnose jumps into the try of a function-try-block. The reason is quite simple: from cp_parser_function_try_block we call cp_parser_ctor_initializer_opt_and_function_body which calls cp_parser_function_body, which always passes false to cp_parser_compound_statement as third argument.

Thus it seems to me that the straightforward way to fix this is making sure a true reaches the latter when parsing a function-try-block, then it must work because try-blocks do exactly that and are already fine.

Bootstrapped and tested x86_64-linux.

Thanks,
Paolo.

///////////////////////
/cp
2012-05-24  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/32080
        * parser.c (cp_parser_ctor_initializer_opt_and_function_body,
        cp_parser_function_body): Add a bool parameter, true when parsing
        a function-try-block.
        (cp_parser_function_try_block): Pass true to the above.
        (cp_parser_function_definition_after_declarator,
        cp_parser_function_transaction): Adjust.

/testsuite
2012-05-24  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/32080
        * g++.dg/eh/goto2.C: New.

Index: testsuite/g++.dg/eh/goto2.C
===================================================================
--- testsuite/g++.dg/eh/goto2.C (revision 0)
+++ testsuite/g++.dg/eh/goto2.C (revision 0)
@@ -0,0 +1,12 @@
+// PR c++/32080
+
+void f()
+try
+  {
+    goto l2;       // { dg-error "from here" }
+  l1: ;            // { dg-error "jump to label 'l1'" }
+  } catch (...)
+  {
+  l2: ;            // { dg-error "jump to label 'l2'|enters catch block" }
+    goto l1;       // { dg-error "from here|enters try block" }
+  }
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 187822)
+++ cp/parser.c (working copy)
@@ -1989,7 +1989,7 @@ static cp_parameter_declarator *cp_parser_paramete
 static tree cp_parser_default_argument 
   (cp_parser *, bool);
 static void cp_parser_function_body
-  (cp_parser *);
+  (cp_parser *, bool);
 static tree cp_parser_initializer
   (cp_parser *, bool *, bool *);
 static tree cp_parser_initializer_clause
@@ -2000,7 +2000,7 @@ static VEC(constructor_elt,gc) *cp_parser_initiali
   (cp_parser *, bool *);
 
 static bool cp_parser_ctor_initializer_opt_and_function_body
-  (cp_parser *);
+  (cp_parser *, bool);
 
 /* Classes [gram.class] */
 
@@ -17395,16 +17395,18 @@ cp_parser_default_argument (cp_parser *parser, boo
      compound_statement  */
 
 static void
-cp_parser_function_body (cp_parser *parser)
+cp_parser_function_body (cp_parser *parser, bool in_function_try_block)
 {
-  cp_parser_compound_statement (parser, NULL, false, true);
+  cp_parser_compound_statement (parser, NULL, in_function_try_block, true);
 }
 
 /* Parse a ctor-initializer-opt followed by a function-body.  Return
-   true if a ctor-initializer was present.  */
+   true if a ctor-initializer was present.  When IN_FUNCTION_TRY_BLOCK
+   is true we are parsing a function-try-block.  */
 
 static bool
-cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser)
+cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser,
+                                                 bool in_function_try_block)
 {
   tree body, list;
   bool ctor_initializer_p;
@@ -17431,7 +17433,7 @@ static bool
        last = STATEMENT_LIST_TAIL (list)->stmt;
     }
   /* Parse the function-body.  */
-  cp_parser_function_body (parser);
+  cp_parser_function_body (parser, in_function_try_block);
   if (check_body_p)
     check_constexpr_ctor_body (last, list);
   /* Finish the function body.  */
@@ -19707,8 +19709,8 @@ cp_parser_function_try_block (cp_parser* parser)
   /* Let the rest of the front end know where we are.  */
   try_block = begin_function_try_block (&compound_stmt);
   /* Parse the function-body.  */
-  ctor_initializer_p
-    = cp_parser_ctor_initializer_opt_and_function_body (parser);
+  ctor_initializer_p = cp_parser_ctor_initializer_opt_and_function_body
+    (parser, /*in_function_try_block=*/true);
   /* We're done with the `try' part.  */
   finish_function_try_block (try_block);
   /* Parse the handlers.  */
@@ -21048,8 +21050,8 @@ cp_parser_function_definition_after_declarator (cp
   else if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
     ctor_initializer_p = cp_parser_function_try_block (parser);
   else
-    ctor_initializer_p
-      = cp_parser_ctor_initializer_opt_and_function_body (parser);
+    ctor_initializer_p = cp_parser_ctor_initializer_opt_and_function_body
+      (parser, /*in_function_try_block=*/false);
 
   finish_lambda_scope ();
 
@@ -27224,8 +27226,8 @@ cp_parser_function_transaction (cp_parser *parser,
   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
     ctor_initializer_p = cp_parser_function_try_block (parser);
   else
-    ctor_initializer_p
-      = cp_parser_ctor_initializer_opt_and_function_body (parser);
+    ctor_initializer_p = cp_parser_ctor_initializer_opt_and_function_body
+      (parser, /*in_function_try_block=*/false);
 
   parser->in_transaction = old_in;
 

Reply via email to