diff options
author | Paolo Carlini <paolo@gcc.gnu.org> | 2019-08-14 08:50:55 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2019-08-14 08:50:55 +0000 |
commit | 777e426772f80cd101b49abb842ea621e89c433e (patch) | |
tree | ec7e65088f6c4d4ca22e3c5b11934e676ea3a01e /gcc | |
parent | e272312308192b56937d3e3e1cb62e68fe2de833 (diff) | |
download | gcc-777e426772f80cd101b49abb842ea621e89c433e.zip gcc-777e426772f80cd101b49abb842ea621e89c433e.tar.gz gcc-777e426772f80cd101b49abb842ea621e89c433e.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/decl.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/typedef9.C | 4 |
2 files changed, 13 insertions, 15 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index b849630..ff3b90d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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); diff --git a/gcc/testsuite/g++.dg/parse/typedef9.C b/gcc/testsuite/g++.dg/parse/typedef9.C index 7788f78..2e7d672 100644 --- a/gcc/testsuite/g++.dg/parse/typedef9.C +++ b/gcc/testsuite/g++.dg/parse/typedef9.C @@ -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" } }; |