Hi,

in this C++11 reject valid parsing issue, in a function-try-block we reject:

    try
    : f { func }  { }                     (1)

and we normally accept the C++98:

    try
    : f ( func )  { }                     (2)

Considering cp_parser_save_member_function_body, I think that a neat solution would be simply consuming first any 'try' keyword and then proceeding as usual. What is happening now is that, later on, the closed curly brace in 'f{ func }' is confused with the closed curly brace of (2) and things wrong when the former is not followed by 'catch'.

Tested x86_64-linux.

Thanks,
Paolo.

/////////////////////////
/cp
2013-06-23  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/57682
        * parser.c (cp_parser_save_member_function_body): Handle correctly
        curly braces in function-try-block mem-initializers.

/testsuite
2013-06-23  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/57682
        * g++.dg/cpp0x/initlist72.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 200350)
+++ cp/parser.c (working copy)
@@ -22797,6 +22797,9 @@ cp_parser_save_member_function_body (cp_parser* pa
   /* Save away the tokens that make up the body of the
      function.  */
   first = parser->lexer->next_token;
+  /* Handle function try blocks.  */
+  if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
+    cp_lexer_consume_token (parser->lexer);
   /* We can have braced-init-list mem-initializers before the fn body.  */
   if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
     {
Index: testsuite/g++.dg/cpp0x/initlist72.C
===================================================================
--- testsuite/g++.dg/cpp0x/initlist72.C (revision 0)
+++ testsuite/g++.dg/cpp0x/initlist72.C (working copy)
@@ -0,0 +1,13 @@
+// PR c++/57682
+// { dg-do compile { target c++11 } }
+
+struct Class
+{
+  Class (int func)
+  try
+  : f { func }  { }
+  catch ( ... ) { }
+
+private:
+  int f;
+};

Reply via email to