Commit 777e4267 by Paolo Carlini

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

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
parent e2723123
......@@ -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);
......
// 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" }
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment