diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 050f437f6d7d..70c9bd380bd5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,15 @@ +2001-07-26 Nathan Sidwell + + * decl.c (last_function_parm_tags): Remove. + (current_function_parm_tags): Remove. + (init_decl_processing): Adjust. + (start_function): Adjust. + (store_parm_decls): Adjust. + + PR c++/3152 + * decl.c (grokdeclarator): Detect when a function typedef is + declaring a function, and create last_function_parms correctly. + 2001-07-25 Jason Merrill * call.c (joust): Only prefer a non-builtin candidate to a builtin diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 4bbf2e0f5d48..c9867da52099 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -243,14 +243,8 @@ tree static_aggregates; tree integer_two_node, integer_three_node; -/* Parsing a function declarator leaves here a chain of structure - and enum types declared in the parmlist. */ - -static tree last_function_parm_tags; - /* Similar, for last_function_parm_tags. */ tree last_function_parms; -static tree current_function_parm_tags; /* A list of all LABEL_DECLs in the function that have names. Here so we can clear out their names' definitions at the end of the @@ -6565,8 +6559,6 @@ init_decl_processing () ggc_add_tree_root (&static_dtors, 1); ggc_add_tree_root (&lastiddecl, 1); - ggc_add_tree_root (&last_function_parm_tags, 1); - ggc_add_tree_root (¤t_function_parm_tags, 1); ggc_add_tree_root (&last_function_parms, 1); ggc_add_tree_root (&error_mark_list, 1); @@ -11101,6 +11093,26 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); } + /* Detect where we're using a typedef of function type to declare a + function. last_function_parms will not be set, so we must create + it now. */ + + if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE) + { + tree decls = NULL_TREE; + tree args; + + for (args = TYPE_ARG_TYPES (type); args; args = TREE_CHAIN (args)) + { + tree decl = build_decl (PARM_DECL, NULL_TREE, TREE_VALUE (args)); + + TREE_CHAIN (decl) = decls; + decls = decl; + } + + last_function_parms = nreverse (decls); + } + /* If this is a type name (such as, in a cast or sizeof), compute the type and return it now. */ @@ -13296,7 +13308,6 @@ start_function (declspecs, declarator, attrs, flags) } last_function_parms = DECL_ARGUMENTS (decl1); - last_function_parm_tags = NULL_TREE; } else { @@ -13403,7 +13414,6 @@ start_function (declspecs, declarator, attrs, flags) /* Save the parm names or decls from this function's declarator where store_parm_decls will find them. */ current_function_parms = last_function_parms; - current_function_parm_tags = last_function_parm_tags; /* Make sure the parameter and return types are reasonable. When you declare a function, these types can be incomplete, but they @@ -13630,9 +13640,6 @@ store_parm_decls (current_function_parms) int parms_have_cleanups = 0; tree cleanups = NULL_TREE; - /* This is a list of types declared among parms in a prototype. */ - tree parmtags = current_function_parm_tags; - /* This is a chain of any other decls that came in among the parm declarations. If a parm is declared with enum {foo, bar} x; then CONST_DECLs for foo and bar are put here. */ @@ -13690,7 +13697,7 @@ store_parm_decls (current_function_parms) function. This is all and only the PARM_DECLs that were pushed into scope by the loop above. */ DECL_ARGUMENTS (fndecl) = getdecls (); - storetags (chainon (parmtags, gettags ())); + storetags (gettags ()); } else DECL_ARGUMENTS (fndecl) = NULL_TREE; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 805bbb5ebe66..c06c779aa6ae 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-07-26 Nathan Sidwell + + * g++.old-deja/g++.other/crash42.C: New test. + 2001-07-26 Neil Booth * gcc.dg/cpp/extratokens.c: Fix. diff --git a/gcc/testsuite/g++.old-deja/g++.other/crash42.C b/gcc/testsuite/g++.old-deja/g++.other/crash42.C new file mode 100644 index 000000000000..be316ac6645c --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/crash42.C @@ -0,0 +1,17 @@ +// Build don't link: +// Special g++ Options: -g +// +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 25 Jul 2001 + +// Bug 3152. Using a typedef to declare a function used an unset +// global variable, last_function_parms. + +struct actor +{ + typedef bool (operation)(); + + operation a; + operation b; + operation c; +};