Hi,

this old issue is about default arguments not rejected for function typedefs. We have got infrastructure for that - parser->default_arg_ok_p - and it seems to me that we can safely set the flag to false in cp_parser_init_declarator when the decl_specifier has ds_typedef set. Tested x86_64-linux.

Thanks,
Paolo.

////////////////////////
/cp
2013-07-05  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/28262
        * parser.c (cp_parser_init_declarator): If we are parsing a typedef
        set parser->default_arg_ok_p to false before cp_parser_declarator.

/testsuite
2013-07-05  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/28262
        * g++.dg/parse/defarg16.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 200725)
+++ cp/parser.c (working copy)
@@ -16182,6 +16182,7 @@ cp_parser_init_declarator (cp_parser* parser,
   bool friend_p;
   tree pushed_scope = NULL_TREE;
   bool range_for_decl_p = false;
+  bool saved_default_arg_ok_p = parser->default_arg_ok_p;
 
   /* Gather the attributes that were provided with the
      decl-specifiers.  */
@@ -16192,6 +16193,10 @@ cp_parser_init_declarator (cp_parser* parser,
   if (function_definition_p)
     *function_definition_p = false;
 
+  /* Default arguments are only permitted for function parameters.  */
+  if (decl_spec_seq_has_spec_p (decl_specifiers, ds_typedef))
+    parser->default_arg_ok_p = false;
+
   /* Defer access checks while parsing the declarator; we cannot know
      what names are accessible until we know what is being
      declared.  */
@@ -16207,6 +16212,8 @@ cp_parser_init_declarator (cp_parser* parser,
   /* Gather up the deferred checks.  */
   stop_deferring_access_checks ();
 
+  parser->default_arg_ok_p = saved_default_arg_ok_p;
+
   /* If the DECLARATOR was erroneous, there's no need to go
      further.  */
   if (declarator == cp_error_declarator)
Index: testsuite/g++.dg/parse/defarg16.C
===================================================================
--- testsuite/g++.dg/parse/defarg16.C   (revision 0)
+++ testsuite/g++.dg/parse/defarg16.C   (working copy)
@@ -0,0 +1,4 @@
+// PR c++/28262
+
+typedef void (funcptrhack) (int = 10);   // { dg-error "default arguments" }
+typedef funcptrhack * funcptr;

Reply via email to