decl.c (grokdeclarator): Check here for typedef a function definition or a member function definition.

/cp
2019-08-14  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (grokdeclarator): Check here for typedef a function
	definition or a member function definition.
	(start_function): Adjust.
	(grokmethod): Likewise.

/testsuite
2019-08-14  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/parse/typedef9.C: Test locations too.

From-SVN: r274431
This commit is contained in:
Paolo Carlini 2019-08-14 08:50:55 +00:00
parent e272312308
commit 777e426772
2 changed files with 13 additions and 15 deletions

View File

@ -12164,6 +12164,17 @@ grokdeclarator (const cp_declarator *declarator,
bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
tree decl;
if (funcdef_flag)
{
if (decl_context == NORMAL)
error_at (id_loc,
"typedef may not be a function definition");
else
error_at (id_loc,
"typedef may not be a member function definition");
return error_mark_node;
}
/* This declaration:
typedef void f(int) const;
@ -15776,13 +15787,6 @@ start_function (cp_decl_specifier_seq *declspecs,
invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
if (decl1 == error_mark_node)
return false;
/* If the declarator is not suitable for a function definition,
cause a syntax error. */
if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
{
error ("invalid function declaration");
return false;
}
if (DECL_MAIN_P (decl1))
/* main must return int. grokfndecl should have corrected it
@ -16437,12 +16441,6 @@ grokmethod (cp_decl_specifier_seq *declspecs,
if (fndecl == error_mark_node)
return error_mark_node;
if (fndecl == NULL || TREE_CODE (fndecl) != FUNCTION_DECL)
{
error ("invalid member function declaration");
return error_mark_node;
}
if (attrlist)
cplus_decl_attributes (&fndecl, attrlist, 0);

View File

@ -1,8 +1,8 @@
// PR c++/38794
// { dg-do compile }
typedef void foo () {} // { dg-error "invalid function declaration" }
typedef void foo () {} // { dg-error "14:typedef may not be a function definition" }
struct S
{
typedef int bar (void) { return 0; } // { dg-error "invalid member function declaration" }
typedef int bar (void) { return 0; } // { dg-error "15:typedef may not be a member function definition" }
};