This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Diagnose typedef with function definition (PR c++/38794)


Hi!

The PR27102 patch removed error ("invalid function declaration") from
cp_parser_function_definition_from_specifiers_and_declarator if
(!success_p), so we no longer diagnose typedef with function definition,
just silently return error_mark_node from it.

The following patch re-adds the error to start_function, only when
grokdeclarator hasn't returned FUNCTION_DECL nor error_mark_node
(in the latter case we assume the diagnostics has been already reported).

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2009-01-12  Jakub Jelinek  <jakub@redhat.com>

	PR c++/38794
	* decl.c (start_function): If grokdeclarator hasn't returned
	FUNCTION_DECL nor error_mark_node, issue diagnostics.

	* g++.dg/parse/typedef9.C: New test.

--- gcc/cp/decl.c.jj	2009-01-12 12:46:14.000000000 +0100
+++ gcc/cp/decl.c	2009-01-12 12:58:49.000000000 +0100
@@ -11771,10 +11771,15 @@ start_function (cp_decl_specifier_seq *d
   tree decl1;
 
   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
+  if (decl1 == error_mark_node)
+    return 0;
   /* If the declarator is not suitable for a function definition,
      cause a syntax error.  */
   if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
-    return 0;
+    {
+      error ("invalid function declaration");
+      return 0;
+    }
 
   if (DECL_MAIN_P (decl1))
     /* main must return int.  grokfndecl should have corrected it
--- gcc/testsuite/g++.dg/parse/typedef9.C.jj	2009-01-12 13:01:37.000000000 +0100
+++ gcc/testsuite/g++.dg/parse/typedef9.C	2009-01-12 13:03:40.000000000 +0100
@@ -0,0 +1,8 @@
+// PR c++/38794
+// { dg-do compile }
+
+typedef void foo () {}	// { dg-error "invalid function declaration" }
+struct S
+{
+  typedef int bar (void) { return 0; } // { dg-error "invalid member function declaration" }
+};

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]