This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Diagnose typedef with function definition (PR c++/38794)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 12 Jan 2009 14:06:55 +0100
- Subject: [C++ PATCH] Diagnose typedef with function definition (PR c++/38794)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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