diff options
-rw-r--r-- | contrib/gcc/cp/decl.c | 12301 |
1 files changed, 5951 insertions, 6350 deletions
diff --git a/contrib/gcc/cp/decl.c b/contrib/gcc/cp/decl.c index bd69ca5..6b5dd8b 100644 --- a/contrib/gcc/cp/decl.c +++ b/contrib/gcc/cp/decl.c @@ -1,5 +1,6 @@ /* Process declarations and variables for C compiler. - Copyright (C) 1988, 92-98, 1999 Free Software Foundation, Inc. + Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, + 2001, 2002 Free Software Foundation, Inc. Contributed by Michael Tiemann (tiemann@cygnus.com) This file is part of GNU CC. @@ -33,424 +34,204 @@ Boston, MA 02111-1307, USA. */ #include "system.h" #include "tree.h" #include "rtl.h" +#include "expr.h" #include "flags.h" #include "cp-tree.h" +#include "tree-inline.h" #include "decl.h" #include "lex.h" -#include <signal.h> -#include "obstack.h" -#include "defaults.h" #include "output.h" #include "except.h" #include "toplev.h" #include "../hash.h" +#include "ggc.h" +#include "tm_p.h" +#include "target.h" +#include "c-common.h" +#include "diagnostic.h" -#define obstack_chunk_alloc xmalloc -#define obstack_chunk_free free - -extern tree builtin_return_address_fndecl; - -extern struct obstack permanent_obstack; -extern struct obstack* saveable_obstack; - -extern int current_class_depth; - -extern tree static_ctors, static_dtors; - -extern int static_labelno; - -extern tree current_namespace; -extern tree global_namespace; - -extern void (*print_error_function) PROTO((char *)); -extern int (*valid_lang_attribute) PROTO ((tree, tree, tree, tree)); - -/* Obstack used for remembering local class declarations (like - enums and static (const) members. */ -#include "stack.h" -struct obstack decl_obstack; -static struct stack_level *decl_stack; - -#ifndef CHAR_TYPE_SIZE -#define CHAR_TYPE_SIZE BITS_PER_UNIT -#endif - -#ifndef SHORT_TYPE_SIZE -#define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) -#endif - -#ifndef INT_TYPE_SIZE -#define INT_TYPE_SIZE BITS_PER_WORD -#endif - -#ifndef LONG_TYPE_SIZE -#define LONG_TYPE_SIZE BITS_PER_WORD -#endif - -#ifndef LONG_LONG_TYPE_SIZE -#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) -#endif - -#ifndef WCHAR_UNSIGNED -#define WCHAR_UNSIGNED 0 -#endif - -#ifndef FLOAT_TYPE_SIZE -#define FLOAT_TYPE_SIZE BITS_PER_WORD -#endif - -#ifndef DOUBLE_TYPE_SIZE -#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) -#endif - -#ifndef LONG_DOUBLE_TYPE_SIZE -#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) -#endif +extern const struct attribute_spec *lang_attribute_table; #ifndef BOOL_TYPE_SIZE -#ifdef SLOW_BYTE_ACCESS -#define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (POINTER_SIZE) : (CHAR_TYPE_SIZE)) -#else +/* `bool' has size and alignment `1', on all platforms. */ #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE #endif -#endif - -/* We let tm.h override the types used here, to handle trivial differences - such as the choice of unsigned int or long unsigned int for size_t. - When machines start needing nontrivial differences in the size type, - it would be best to do something here to figure out automatically - from other information what type to use. */ - -#ifndef SIZE_TYPE -#define SIZE_TYPE "long unsigned int" -#endif -#ifndef PTRDIFF_TYPE -#define PTRDIFF_TYPE "long int" -#endif - -#ifndef WCHAR_TYPE -#define WCHAR_TYPE "int" -#endif +static tree grokparms PARAMS ((tree)); +static const char *redeclaration_error_message PARAMS ((tree, tree)); -static tree grokparms PROTO((tree, int)); -static tree lookup_nested_type PROTO((tree, tree)); -static const char *redeclaration_error_message PROTO((tree, tree)); - -static struct stack_level *push_decl_level PROTO((struct stack_level *, - struct obstack *)); -static void push_binding_level PROTO((struct binding_level *, int, +static void push_binding_level PARAMS ((struct binding_level *, int, int)); -static void pop_binding_level PROTO((void)); -static void suspend_binding_level PROTO((void)); -static void resume_binding_level PROTO((struct binding_level *)); -static struct binding_level *make_binding_level PROTO((void)); -static void declare_namespace_level PROTO((void)); -static void signal_catch PROTO((int)) ATTRIBUTE_NORETURN; -static void storedecls PROTO((tree)); -static void require_complete_types_for_parms PROTO((tree)); -static void push_overloaded_decl_1 PROTO((tree)); -static int ambi_op_p PROTO((tree)); -static int unary_op_p PROTO((tree)); -static tree store_bindings PROTO((tree, tree)); -static tree lookup_tag_reverse PROTO((tree, tree)); -static tree obscure_complex_init PROTO((tree, tree)); -static tree maybe_build_cleanup_1 PROTO((tree, tree)); -static tree lookup_name_real PROTO((tree, int, int, int)); -static void warn_extern_redeclared_static PROTO((tree, tree)); -static void grok_reference_init PROTO((tree, tree, tree)); -static tree grokfndecl PROTO((tree, tree, tree, tree, int, +static void pop_binding_level PARAMS ((void)); +static void suspend_binding_level PARAMS ((void)); +static void resume_binding_level PARAMS ((struct binding_level *)); +static struct binding_level *make_binding_level PARAMS ((void)); +static void declare_namespace_level PARAMS ((void)); +static int decl_jump_unsafe PARAMS ((tree)); +static void storedecls PARAMS ((tree)); +static void require_complete_types_for_parms PARAMS ((tree)); +static int ambi_op_p PARAMS ((enum tree_code)); +static int unary_op_p PARAMS ((enum tree_code)); +static tree store_bindings PARAMS ((tree, tree)); +static tree lookup_tag_reverse PARAMS ((tree, tree)); +static tree obscure_complex_init PARAMS ((tree, tree)); +static tree lookup_name_real PARAMS ((tree, int, int, int)); +static void push_local_name PARAMS ((tree)); +static void warn_extern_redeclared_static PARAMS ((tree, tree)); +static tree grok_reference_init PARAMS ((tree, tree, tree)); +static tree grokfndecl PARAMS ((tree, tree, tree, tree, int, enum overload_flags, tree, tree, int, int, int, int, int, int, tree)); -static tree grokvardecl PROTO((tree, tree, RID_BIT_TYPE *, int, int, tree)); -static tree lookup_tag PROTO((enum tree_code, tree, +static tree grokvardecl PARAMS ((tree, tree, RID_BIT_TYPE *, int, int, tree)); +static tree lookup_tag PARAMS ((enum tree_code, tree, struct binding_level *, int)); static void set_identifier_type_value_with_scope - PROTO((tree, tree, struct binding_level *)); -static void record_builtin_type PROTO((enum rid, const char *, tree)); -static void record_unknown_type PROTO((tree, const char *)); -static int member_function_or_else PROTO((tree, tree, const char *)); -static void bad_specifiers PROTO((tree, const char *, int, int, int, int, + PARAMS ((tree, tree, struct binding_level *)); +static void record_unknown_type PARAMS ((tree, const char *)); +static tree build_library_fn_1 PARAMS ((tree, enum tree_code, tree)); +static int member_function_or_else PARAMS ((tree, tree, enum overload_flags)); +static void bad_specifiers PARAMS ((tree, const char *, int, int, int, int, int)); -static void lang_print_error_function PROTO((char *)); -static tree maybe_process_template_type_declaration PROTO((tree, int, struct binding_level*)); -static void check_for_uninitialized_const_var PROTO((tree)); -static unsigned long typename_hash PROTO((hash_table_key)); -static boolean typename_compare PROTO((hash_table_key, hash_table_key)); -static void push_binding PROTO((tree, tree, struct binding_level*)); -static int add_binding PROTO((tree, tree)); -static void pop_binding PROTO((tree, tree)); -static tree local_variable_p PROTO((tree)); -static tree find_binding PROTO((tree, tree)); -static tree select_decl PROTO((tree, int)); -static tree unqualified_namespace_lookup PROTO((tree, int)); -static int lookup_flags PROTO((int, int)); -static tree qualify_lookup PROTO((tree, int)); -static tree record_builtin_java_type PROTO((const char *, int)); -static const char *tag_name PROTO((enum tag_types code)); -static void find_class_binding_level PROTO((void)); -static struct binding_level *innermost_nonclass_level PROTO((void)); -static void finish_dtor PROTO((void)); -static void finish_ctor PROTO((int)); -static tree poplevel_class PROTO((void)); -static void warn_about_implicit_typename_lookup PROTO((tree, tree)); -static int walk_namespaces_r PROTO((tree, walk_namespaces_fn, void *)); -static int walk_globals_r PROTO((tree, void *)); +static tree maybe_process_template_type_declaration PARAMS ((tree, int, struct binding_level*)); +static void check_for_uninitialized_const_var PARAMS ((tree)); +static unsigned long typename_hash PARAMS ((hash_table_key)); +static bool typename_compare PARAMS ((hash_table_key, hash_table_key)); +static void push_binding PARAMS ((tree, tree, struct binding_level*)); +static int add_binding PARAMS ((tree, tree)); +static void pop_binding PARAMS ((tree, tree)); +static tree local_variable_p_walkfn PARAMS ((tree *, int *, void *)); +static tree find_binding PARAMS ((tree, tree)); +static tree select_decl PARAMS ((tree, int)); +static int lookup_flags PARAMS ((int, int)); +static tree qualify_lookup PARAMS ((tree, int)); +static tree record_builtin_java_type PARAMS ((const char *, int)); +static const char *tag_name PARAMS ((enum tag_types code)); +static void find_class_binding_level PARAMS ((void)); +static struct binding_level *innermost_nonclass_level PARAMS ((void)); +static void warn_about_implicit_typename_lookup PARAMS ((tree, tree)); +static int walk_namespaces_r PARAMS ((tree, walk_namespaces_fn, void *)); +static int walk_globals_r PARAMS ((tree, void *)); +static void add_decl_to_level PARAMS ((tree, struct binding_level *)); +static tree make_label_decl PARAMS ((tree, int)); +static void use_label PARAMS ((tree)); +static void check_previous_goto_1 PARAMS ((tree, struct binding_level *, tree, + const char *, int)); +static void check_previous_goto PARAMS ((struct named_label_use_list *)); +static void check_switch_goto PARAMS ((struct binding_level *)); +static void check_previous_gotos PARAMS ((tree)); +static void pop_label PARAMS ((tree, tree)); +static void pop_labels PARAMS ((tree)); +static void maybe_deduce_size_from_array_init PARAMS ((tree, tree)); +static void layout_var_decl PARAMS ((tree)); +static void maybe_commonize_var PARAMS ((tree)); +static tree check_initializer PARAMS ((tree, tree)); +static void make_rtl_for_nonlocal_decl PARAMS ((tree, tree, const char *)); +static void push_cp_function_context PARAMS ((struct function *)); +static void pop_cp_function_context PARAMS ((struct function *)); +static void mark_binding_level PARAMS ((void *)); +static void mark_named_label_lists PARAMS ((void *, void *)); +static void mark_cp_function_context PARAMS ((struct function *)); +static void mark_saved_scope PARAMS ((void *)); +static void mark_lang_function PARAMS ((struct cp_language_function *)); +static void save_function_data PARAMS ((tree)); +static void check_function_type PARAMS ((tree, tree)); +static void destroy_local_var PARAMS ((tree)); +static void begin_constructor_body PARAMS ((void)); +static void finish_constructor_body PARAMS ((void)); +static void begin_destructor_body PARAMS ((void)); +static void finish_destructor_body PARAMS ((void)); +static tree create_array_type_for_decl PARAMS ((tree, tree, tree)); +static tree get_atexit_node PARAMS ((void)); +static tree get_dso_handle_node PARAMS ((void)); +static tree start_cleanup_fn PARAMS ((void)); +static void end_cleanup_fn PARAMS ((void)); +static tree cp_make_fname_decl PARAMS ((tree, int)); +static void initialize_predefined_identifiers PARAMS ((void)); +static tree check_special_function_return_type + PARAMS ((special_function_kind, tree, tree)); +static tree push_cp_library_fn PARAMS ((enum tree_code, tree)); +static tree build_cp_library_fn PARAMS ((tree, enum tree_code, tree)); +static void store_parm_decls PARAMS ((tree)); +static int cp_missing_noreturn_ok_p PARAMS ((tree)); #if defined (DEBUG_CP_BINDING_LEVELS) -static void indent PROTO((void)); +static void indent PARAMS ((void)); #endif -/* A node which has tree code ERROR_MARK, and whose type is itself. - All erroneous expressions are replaced with this node. All functions - that accept nodes as arguments should avoid generating error messages - if this node is one of the arguments, since it is undesirable to get - multiple error messages from one error in the input. */ - -tree error_mark_node; - /* Erroneous argument lists can use this *IFF* they do not modify it. */ tree error_mark_list; -/* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ - -tree short_integer_type_node; -tree integer_type_node; -tree long_integer_type_node; -tree long_long_integer_type_node; - -tree short_unsigned_type_node; -tree unsigned_type_node; -tree long_unsigned_type_node; -tree long_long_unsigned_type_node; - -tree ptrdiff_type_node; - -tree unsigned_char_type_node; -tree signed_char_type_node; -tree char_type_node; -tree wchar_type_node; -tree signed_wchar_type_node; -tree unsigned_wchar_type_node; - -tree wchar_decl_node; - -tree float_type_node; -tree double_type_node; -tree long_double_type_node; - -tree complex_integer_type_node; -tree complex_float_type_node; -tree complex_double_type_node; -tree complex_long_double_type_node; - -tree intQI_type_node; -tree intHI_type_node; -tree intSI_type_node; -tree intDI_type_node; -#if HOST_BITS_PER_WIDE_INT >= 64 -tree intTI_type_node; -#endif - -tree unsigned_intQI_type_node; -tree unsigned_intHI_type_node; -tree unsigned_intSI_type_node; -tree unsigned_intDI_type_node; -#if HOST_BITS_PER_WIDE_INT >= 64 -tree unsigned_intTI_type_node; -#endif - -tree java_byte_type_node; -tree java_short_type_node; -tree java_int_type_node; -tree java_long_type_node; -tree java_float_type_node; -tree java_double_type_node; -tree java_char_type_node; -tree java_boolean_type_node; +/* The following symbols are subsumed in the cp_global_trees array, and + listed here individually for documentation purposes. -/* A VOID_TYPE node, and the same, packaged in a TREE_LIST. */ + C++ extensions + tree wchar_decl_node; -tree void_type_node, void_list_node; -tree void_zero_node; + tree vtable_entry_type; + tree delta_type_node; + tree __t_desc_type_node; + tree ti_desc_type_node; + tree bltn_desc_type_node, ptr_desc_type_node; + tree ary_desc_type_node, func_desc_type_node, enum_desc_type_node; + tree class_desc_type_node, si_class_desc_type_node, vmi_class_desc_type_node; + tree ptm_desc_type_node; + tree base_desc_type_node; -/* Nodes for types `void *' and `const void *'. */ + tree class_type_node, record_type_node, union_type_node, enum_type_node; + tree unknown_type_node; -tree ptr_type_node; -tree const_ptr_type_node; + Array type `vtable_entry_type[]' -/* Nodes for types `char *' and `const char *'. */ + tree vtbl_type_node; + tree vtbl_ptr_type_node; -tree string_type_node, const_string_type_node; + Namespaces, -/* Type `char[256]' or something like it. - Used when an array of char is needed and the size is irrelevant. */ + tree std_node; + tree abi_node; -tree char_array_type_node; - -/* Type `int[256]' or something like it. - Used when an array of int needed and the size is irrelevant. */ - -tree int_array_type_node; - -/* Type `wchar_t[256]' or something like it. - Used when a wide string literal is created. */ - -tree wchar_array_type_node; - -/* The bool data type, and constants */ -tree boolean_type_node, boolean_true_node, boolean_false_node; - -/* Type `int ()' -- used for implicit declaration of functions. */ - -tree default_function_type; - -/* Function types `double (double)' and `double (double, double)', etc. */ + A FUNCTION_DECL which can call `abort'. Not necessarily the + one that the user will declare, but sufficient to be called + by routines that want to abort the program. -static tree double_ftype_double, double_ftype_double_double; -static tree int_ftype_int, long_ftype_long; -static tree float_ftype_float; -static tree ldouble_ftype_ldouble; + tree abort_fndecl; -/* Function type `int (const void *, const void *, size_t)' */ -static tree int_ftype_cptr_cptr_sizet; + The FUNCTION_DECL for the default `::operator delete'. -/* C++ extensions */ -tree vtable_entry_type; -tree delta_type_node; -#if 0 -/* Old rtti stuff. */ -tree __baselist_desc_type_node; -tree __i_desc_type_node, __m_desc_type_node; -tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; -#endif -tree __t_desc_type_node; -#if 0 -tree __tp_desc_type_node; -#endif -tree __access_mode_type_node; -tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node; -tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node; -tree __ptmf_desc_type_node, __ptmd_desc_type_node; -#if 0 -/* Not needed yet? May be needed one day? */ -tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type; -tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type; -tree __ptmf_desc_array_type, __ptmd_desc_array_type; -#endif + tree global_delete_fndecl; -/* This is the identifier __vlist. */ -tree vlist_identifier; + Used by RTTI + tree type_info_type_node, tinfo_decl_id, tinfo_decl_type; + tree tinfo_var_id; -/* This is the type _Vlist = vtable_entry_type**. */ -tree vlist_type_node; +*/ -/* A null pointer of type _Vlist. */ -tree vlist_zero_node; +tree cp_global_trees[CPTI_MAX]; /* Indicates that there is a type value in some namespace, although - that is not necessarily in scope at the moment. */ + that is not necessarily in scope at the moment. */ static tree global_type_node; -tree class_star_type_node; -tree class_type_node, record_type_node, union_type_node, enum_type_node; -tree unknown_type_node; -tree opaque_type_node, signature_type_node; -tree sigtable_entry_type; - -/* Array type `vtable_entry_type[]' */ -tree vtbl_type_node; -tree vtbl_ptr_type_node; - -/* namespace std */ -tree std_node; -int in_std = 0; - /* Expect only namespace names now. */ static int only_namespace_names; -/* In a destructor, the point at which all derived class destroying - has been done, just before any base class destroying will be done. */ - -tree dtor_label; - -/* In a destructor, the last insn emitted after the start of the - function and the parms. */ - -static rtx last_dtor_insn; - -/* In a constructor, the last insn emitted after the start of the - function and the parms, the exception specification and any - function-try-block. The constructor initializers are emitted after - this insn. */ - -static rtx last_parm_cleanup_insn; - -/* In a constructor, the point at which we are ready to return - the pointer to the initialized object. */ +/* Used only for jumps to as-yet undefined labels, since jumps to + defined labels can have their validity checked immediately. */ -tree ctor_label; - -/* A FUNCTION_DECL which can call `abort'. Not necessarily the - one that the user will declare, but sufficient to be called - by routines that want to abort the program. */ - -tree abort_fndecl; - -/* A FUNCTION_DECL for the default `::operator delete'. */ - -tree global_delete_fndecl; - -extern rtx cleanup_label, return_label; - -/* If original DECL_RESULT of current function was a register, - but due to being an addressable named return value, would up - on the stack, this variable holds the named return value's - original location. */ -static rtx original_result_rtx; - -/* Sequence of insns which represents base initialization. */ -tree base_init_expr; - -/* C++: Keep these around to reduce calls to `get_identifier'. - Identifiers for `this' in member functions and the auto-delete - parameter for destructors. */ -tree this_identifier, in_charge_identifier; -tree ctor_identifier, dtor_identifier; -/* Used in pointer to member functions, in vtables, and in sigtables. */ -tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; -tree pfn_or_delta2_identifier, tag_identifier; -tree vt_off_identifier; - -struct named_label_list +struct named_label_use_list { struct binding_level *binding_level; tree names_in_scope; tree label_decl; - char *filename_o_goto; + const char *filename_o_goto; int lineno_o_goto; - struct named_label_list *next; + struct named_label_use_list *next; }; -/* A list (chain of TREE_LIST nodes) of named label uses. - The TREE_PURPOSE field is the list of variables defined - in the label's scope defined at the point of use. - The TREE_VALUE field is the LABEL_DECL used. - The TREE_TYPE field holds `current_binding_level' at the - point of the label's use. +#define named_label_uses cp_function_chain->x_named_label_uses - BWAHAHAAHAHahhahahahaah. No, no, no, said the little chicken. - - Look at the pretty struct named_label_list. See the pretty struct - with the pretty named fields that describe what they do. See the - pretty lack of gratuitous casts. Notice the code got a lot cleaner. - - Used only for jumps to as-yet undefined labels, since - jumps to defined labels can have their validity checked - by stmt.c. */ - -static struct named_label_list *named_label_uses = NULL; +#define local_names cp_function_chain->x_local_names /* A list of objects which have constructors or destructors which reside in the global scope. The decl is stored in @@ -460,133 +241,56 @@ tree static_aggregates; /* -- end of C++ */ -/* Two expressions that are constants with value zero. - The first is of type `int', the second of type `void *'. */ - -tree integer_zero_node; -tree null_pointer_node; - -/* The value for __null (NULL), namely, a zero of an integer type with - the same number of bits as a pointer. */ -tree null_node; - -/* A node for the integer constants 1, 2, and 3. */ - -tree integer_one_node, integer_two_node, integer_three_node; - -/* While defining an enum type, this is 1 plus the last enumerator - constant value. */ - -static tree enum_next_value; - -/* Nonzero means that there was overflow computing enum_next_value. */ - -static int enum_overflow; - -/* Parsing a function declarator leaves a list of parameter names - or a chain or parameter decls here. */ +/* A node for the integer constants 2, and 3. */ -tree last_function_parms; - -/* Parsing a function declarator leaves here a chain of structure - and enum types declared in the parmlist. */ - -static tree last_function_parm_tags; - -/* After parsing the declarator that starts a function definition, - `start_function' puts here the list of parameter names or chain of decls. - `store_parm_decls' finds it here. */ - -static tree current_function_parms; +tree integer_two_node, integer_three_node; /* Similar, for last_function_parm_tags. */ -static tree current_function_parm_tags; - -/* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function - that have names. Here so we can clear out their names' definitions - at the end of the function. */ - -static tree named_labels; - -/* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ - -static tree shadowed_labels; - -/* The FUNCTION_DECL for the function currently being compiled, - or 0 if between functions. */ -tree current_function_decl; - -/* Set to 0 at beginning of a function definition, set to 1 if - a return statement that specifies a return value is seen. */ - -int current_function_returns_value; - -/* Set to 0 at beginning of a function definition, set to 1 if - a return statement with no argument is seen. */ - -int current_function_returns_null; +tree last_function_parms; -/* Set to 0 at beginning of a function definition, and whenever - a label (case or named) is defined. Set to value of expression - returned from function when that value can be transformed into - a named return value. */ +/* 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 + function, and so we can check the validity of jumps to these labels. */ -tree current_function_return_value; +struct named_label_list +{ + struct binding_level *binding_level; + tree names_in_scope; + tree old_value; + tree label_decl; + tree bad_decls; + struct named_label_list *next; + unsigned int in_try_scope : 1; + unsigned int in_catch_scope : 1; +}; -/* Nonzero means give `double' the same size as `float'. */ +#define named_labels cp_function_chain->x_named_labels -extern int flag_short_double; +/* Nonzero means use the ISO C94 dialect of C. */ -/* Nonzero means don't recognize any builtin functions. */ +int flag_isoc94; -extern int flag_no_builtin; +/* Nonzero means use the ISO C99 dialect of C. */ -/* Nonzero means don't recognize the non-ANSI builtin functions. - -ansi sets this. */ +int flag_isoc99; -extern int flag_no_nonansi_builtin; +/* Nonzero means we are a hosted implementation for code shared with C. */ -/* Nonzero means enable obscure ANSI features and disable GNU extensions - that might cause ANSI-compliant code to be miscompiled. */ +int flag_hosted = 1; -extern int flag_ansi; +/* Nonzero means add default format_arg attributes for functions not + in ISO C. */ -/* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) - objects. */ -extern int flag_huge_objects; +int flag_noniso_default_format_attributes = 1; /* Nonzero if we want to conserve space in the .o files. We do this by putting uninitialized data and runtime initialized data into .common instead of .data at the expense of not flagging multiple definitions. */ extern int flag_conserve_space; - -/* Pointers to the base and current top of the language name stack. */ - -extern tree *current_lang_base, *current_lang_stack; /* C and C++ flags are in decl2.c. */ -/* Set to 0 at beginning of a constructor, set to 1 - if that function does an allocation before referencing its - instance variable. */ -static int current_function_assigns_this; -int current_function_just_assigned_this; - -/* Set to 0 at beginning of a function. Set non-zero when - store_parm_decls is called. Don't call store_parm_decls - if this flag is non-zero! */ -int current_function_parms_stored; - -/* Flag used when debugging spew.c */ - -extern int spew_debug; - -/* This is a copy of the class_shadowed list of the previous class binding - contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs - when entering another class scope (i.e. a cache miss). */ -extern tree previous_class_values; - /* A expression of value 0 with the same precision as a sizetype node, but signed. */ tree signed_size_zero_node; @@ -595,20 +299,27 @@ tree signed_size_zero_node; unit. */ tree anonymous_namespace_name; - -/* Allocate a level of searching. */ +/* The number of function bodies which we are currently processing. + (Zero if we are at namespace scope, one inside the body of a + function, two inside the body of a function in a local class, etc.) */ +int function_depth; -static -struct stack_level * -push_decl_level (stack, obstack) - struct stack_level *stack; - struct obstack *obstack; -{ - struct stack_level tem; - tem.prev = stack; +/* States indicating how grokdeclarator() should handle declspecs marked + with __attribute__((deprecated)). An object declared as + __attribute__((deprecated)) suppresses warnings of uses of other + deprecated items. */ + +enum deprecated_states { + DEPRECATED_NORMAL, + DEPRECATED_SUPPRESS +}; - return push_stack_level (obstack, (char *)&tem, sizeof (tem)); -} +static enum deprecated_states deprecated_state = DEPRECATED_NORMAL; + +/* Set by add_implicitly_declared_members() to keep those members from + being flagged as deprecated or reported as using deprecated + types. */ +int adding_implicit_members = 0; /* For each binding contour we allocate a binding_level structure which records the names defined in that contour. @@ -661,25 +372,27 @@ struct binding_level /* If this binding level is the binding level for a class, then class_shadowed is a TREE_LIST. The TREE_PURPOSE of each node - is the name of an entity bound in the class; the TREE_VALUE is - the IDENTIFIER_CLASS_VALUE before we entered the class. Thus, - when leaving class scope, we can restore the - IDENTIFIER_CLASS_VALUE by walking this list. The TREE_TYPE is + is the name of an entity bound in the class. The TREE_TYPE is the DECL bound by this name in the class. */ tree class_shadowed; /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and - is used for all binding levels. */ + is used for all binding levels. In addition the TREE_VALUE is the + IDENTIFIER_TYPE_VALUE before we entered the class. */ tree type_shadowed; + /* A TREE_LIST. Each TREE_VALUE is the LABEL_DECL for a local + label in this scope. The TREE_PURPOSE is the previous value of + the IDENTIFIER_LABEL VALUE. */ + tree shadowed_labels; + /* For each level (except not the global one), a chain of BLOCK nodes for all the levels that were entered and exited one level down. */ tree blocks; - /* The BLOCK node for this level, if one has been preallocated. - If 0, the BLOCK is allocated (if needed) when the level is popped. */ - tree this_block; + /* The _TYPE node for this level, if parm_flag == 2. */ + tree this_class; /* The binding level which this one is contained in (inherits from). */ struct binding_level *level_chain; @@ -689,19 +402,18 @@ struct binding_level tree incomplete; /* List of VAR_DECLS saved from a previous for statement. - These would be dead in ANSI-conforming code, but might + These would be dead in ISO-conforming code, but might be referenced in ARM-era code. These are stored in a TREE_LIST; the TREE_VALUE is the actual declaration. */ tree dead_vars_from_for; /* 1 for the level that holds the parameters of a function. - 2 for the level that holds a class declaration. - 3 for levels that hold parameter declarations. */ - unsigned parm_flag : 4; + 2 for the level that holds a class declaration. */ + unsigned parm_flag : 2; /* 1 means make a BLOCK for this level regardless of all else. 2 for temporary binding contours created by the compiler. */ - unsigned keep : 3; + unsigned keep : 2; /* Nonzero if this level "doesn't exist" for tags. */ unsigned tag_transparent : 1; @@ -711,19 +423,32 @@ struct binding_level unsigned more_cleanups_ok : 1; unsigned have_cleanups : 1; - /* Nonzero if this level is for storing the decls for template + /* Nonzero if this scope is for storing the decls for template parameters and generic decls; these decls will be discarded and replaced with a TEMPLATE_DECL. */ - unsigned pseudo_global : 1; + unsigned template_parms_p : 1; + + /* Nonzero if this scope corresponds to the `<>' in a + `template <>' clause. Whenever this flag is set, + TEMPLATE_PARMS_P will be set as well. */ + unsigned template_spec_p : 1; /* This is set for a namespace binding level. */ unsigned namespace_p : 1; /* True if this level is that of a for-statement where we need to - worry about ambiguous (ARM or ANSI) scope rules. */ + worry about ambiguous (ARM or ISO) scope rules. */ unsigned is_for_scope : 1; - /* Two bits left for this word. */ + /* True if this level corresponds to a TRY block. Currently this + information is only available while building the tree structure. */ + unsigned is_try_scope : 1; + + /* True if this level corresponds to a CATCH block. Currently this + information is only available while building the tree structure. */ + unsigned is_catch_scope : 1; + + /* Three bits left for this word. */ #if defined(DEBUG_CP_BINDING_LEVELS) /* Binding depth at which this level began. */ @@ -732,14 +457,17 @@ struct binding_level }; #define NULL_BINDING_LEVEL ((struct binding_level *) NULL) - + /* The binding level currently in effect. */ -static struct binding_level *current_binding_level; +#define current_binding_level \ + (cfun && cp_function_chain->bindings \ + ? cp_function_chain->bindings \ + : scope_chain->bindings) /* The binding level of the current class, if any. */ -static struct binding_level *class_binding_level; +#define class_binding_level scope_chain->class_bindings /* A chain of binding_level structures awaiting reuse. */ @@ -751,10 +479,6 @@ static struct binding_level *free_binding_level; static struct binding_level *global_binding_level; -/* Binding level structures are initialized by copying this one. */ - -static struct binding_level clear_binding_level; - /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ static int keep_next_level_flag; @@ -773,7 +497,7 @@ indent () } #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ -static tree pushdecl_with_scope PROTO((tree, struct binding_level *)); +static tree pushdecl_with_scope PARAMS ((tree, struct binding_level *)); static void push_binding_level (newlevel, tag_transparent, keep) @@ -782,11 +506,12 @@ push_binding_level (newlevel, tag_transparent, keep) { /* Add this level to the front of the chain (stack) of levels that are active. */ - *newlevel = clear_binding_level; + memset ((char*) newlevel, 0, sizeof (struct binding_level)); newlevel->level_chain = current_binding_level; current_binding_level = newlevel; newlevel->tag_transparent = tag_transparent; newlevel->more_cleanups_ok = 1; + newlevel->keep = keep; #if defined(DEBUG_CP_BINDING_LEVELS) newlevel->binding_depth = binding_depth; @@ -821,7 +546,7 @@ pop_binding_level () { /* Cannot pop a level, if there are none left to pop. */ if (current_binding_level == global_binding_level) - my_friendly_abort (123); + abort (); } /* Pop the current level, and free the structure for reuse. */ #if defined(DEBUG_CP_BINDING_LEVELS) @@ -860,7 +585,7 @@ suspend_binding_level () { /* Cannot suspend a level, if there are none left to suspend. */ if (current_binding_level == global_binding_level) - my_friendly_abort (123); + abort (); } /* Suspend the current level. */ #if defined(DEBUG_CP_BINDING_LEVELS) @@ -935,15 +660,15 @@ innermost_nonclass_level () /* Nonzero if we are currently in a toplevel binding level. This means either the global binding level or a namespace in a toplevel binding level. Since there are no non-toplevel namespace levels, - this really means any namespace or pseudo-global level. We also - include a class whose context is toplevel. */ + this really means any namespace or template parameter level. We + also include a class whose context is toplevel. */ int toplevel_bindings_p () { struct binding_level *b = innermost_nonclass_level (); - return b->namespace_p || b->pseudo_global; + return b->namespace_p || b->template_parms_p; } /* Nonzero if this is a namespace scope, or if we are defining a class @@ -958,10 +683,15 @@ namespace_bindings_p () return b->namespace_p; } +/* If KEEP is non-zero, make a BLOCK node for the next binding level, + unconditionally. Otherwise, use the normal logic to decide whether + or not to create a BLOCK. */ + void -keep_next_level () +keep_next_level (keep) + int keep; { - keep_next_level_flag = 1; + keep_next_level_flag = keep; } /* Nonzero if the current level needs to have a BLOCK made. */ @@ -976,32 +706,108 @@ kept_level_p () && !current_binding_level->tag_transparent)); } -/* Identify this binding level as a level of parameters. */ - -void -declare_parm_level () -{ - current_binding_level->parm_flag = 1; -} - -void -declare_pseudo_global_level () -{ - current_binding_level->pseudo_global = 1; -} - static void declare_namespace_level () { current_binding_level->namespace_p = 1; } +/* Returns non-zero if this scope was created to store template + parameters. */ + int -pseudo_global_level_p () +template_parm_scope_p () { - struct binding_level *b = innermost_nonclass_level (); + return current_binding_level->template_parms_p; +} + +/* Returns the kind of template specialization we are currently + processing, given that it's declaration contained N_CLASS_SCOPES + explicit scope qualifications. */ + +tmpl_spec_kind +current_tmpl_spec_kind (n_class_scopes) + int n_class_scopes; +{ + int n_template_parm_scopes = 0; + int seen_specialization_p = 0; + int innermost_specialization_p = 0; + struct binding_level *b; + + /* Scan through the template parameter scopes. */ + for (b = current_binding_level; b->template_parms_p; b = b->level_chain) + { + /* If we see a specialization scope inside a parameter scope, + then something is wrong. That corresponds to a declaration + like: + + template <class T> template <> ... + + which is always illegal since [temp.expl.spec] forbids the + specialization of a class member template if the enclosing + class templates are not explicitly specialized as well. */ + if (b->template_spec_p) + { + if (n_template_parm_scopes == 0) + innermost_specialization_p = 1; + else + seen_specialization_p = 1; + } + else if (seen_specialization_p == 1) + return tsk_invalid_member_spec; + + ++n_template_parm_scopes; + } - return b->pseudo_global; + /* Handle explicit instantiations. */ + if (processing_explicit_instantiation) + { + if (n_template_parm_scopes != 0) + /* We've seen a template parameter list during an explicit + instantiation. For example: + + template <class T> template void f(int); + + This is erroneous. */ + return tsk_invalid_expl_inst; + else + return tsk_expl_inst; + } + + if (n_template_parm_scopes < n_class_scopes) + /* We've not seen enough template headers to match all the + specialized classes present. For example: + + template <class T> void R<T>::S<T>::f(int); + + This is illegal; there needs to be one set of template + parameters for each class. */ + return tsk_insufficient_parms; + else if (n_template_parm_scopes == n_class_scopes) + /* We're processing a non-template declaration (even though it may + be a member of a template class.) For example: + + template <class T> void S<T>::f(int); + + The `class T' maches the `S<T>', leaving no template headers + corresponding to the `f'. */ + return tsk_none; + else if (n_template_parm_scopes > n_class_scopes + 1) + /* We've got too many template headers. For example: + + template <> template <class T> void f (T); + + There need to be more enclosing classes. */ + return tsk_excessive_parms; + else + /* This must be a template. It's of the form: + + template <class T> template <class U> void S<T>::f(U); + + This is a specialization if the innermost level was a + specialization; otherwise it's just a definition of the + template. */ + return innermost_specialization_p ? tsk_expl_spec : tsk_template; } void @@ -1019,17 +825,12 @@ void pushlevel (tag_transparent) int tag_transparent; { - register struct binding_level *newlevel = NULL_BINDING_LEVEL; + struct binding_level *newlevel; - /* If this is the top level of a function, - just make sure that NAMED_LABELS is 0. - They should have been set to 0 at the end of the previous function. */ - - if (current_binding_level == global_binding_level) - my_friendly_assert (named_labels == NULL_TREE, 134); + if (cfun && !doing_semantic_analysis_p ()) + return; /* Reuse or create a struct for this binding level. */ - #if defined(DEBUG_CP_BINDING_LEVELS) if (0) #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ @@ -1040,45 +841,94 @@ pushlevel (tag_transparent) free_binding_level = free_binding_level->level_chain; } else - { - newlevel = make_binding_level (); - } + newlevel = make_binding_level (); push_binding_level (newlevel, tag_transparent, keep_next_level_flag); - GNU_xref_start_scope ((HOST_WIDE_INT) newlevel); + GNU_xref_start_scope ((size_t) newlevel); keep_next_level_flag = 0; } +/* We're defining an object of type TYPE. If it needs a cleanup, but + we're not allowed to add any more objects with cleanups to the current + scope, create a new binding level. */ + +void +maybe_push_cleanup_level (type) + tree type; +{ + if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type) + && current_binding_level->more_cleanups_ok == 0) + { + keep_next_level (2); + pushlevel (1); + clear_last_expr (); + add_scope_stmt (/*begin_p=*/1, /*partial_p=*/1); + } +} + +/* Enter a new scope. The KIND indicates what kind of scope is being + created. */ + +void +begin_scope (sk) + scope_kind sk; +{ + pushlevel (0); + + switch (sk) + { + case sk_template_spec: + current_binding_level->template_spec_p = 1; + /* Fall through. */ + + case sk_template_parms: + current_binding_level->template_parms_p = 1; + break; + + default: + abort (); + } +} + +/* Exit the current scope. */ + +void +finish_scope () +{ + poplevel (0, 0, 0); +} + void note_level_for_for () { current_binding_level->is_for_scope = 1; } +/* Record that the current binding level represents a try block. */ + void -pushlevel_temporary (tag_transparent) - int tag_transparent; +note_level_for_try () { - pushlevel (tag_transparent); - current_binding_level->keep = 2; - clear_last_expr (); + current_binding_level->is_try_scope = 1; +} - /* Note we don't call push_momentary() here. Otherwise, it would cause - cleanups to be allocated on the momentary obstack, and they will be - overwritten by the next statement. */ +/* Record that the current binding level represents a catch block. */ - expand_start_bindings (0); +void +note_level_for_catch () +{ + current_binding_level->is_catch_scope = 1; } /* For a binding between a name and an entity at a block scope, this is the `struct binding_level' for the block. */ #define BINDING_LEVEL(NODE) \ - (((struct tree_binding*)NODE)->scope.level) + (((struct tree_binding*)(NODE))->scope.level) -/* These are currently unused, but permanent, CPLUS_BINDING nodes. - They are kept here because they are allocated from the permanent - obstack and cannot be easily freed. */ -static tree free_binding_nodes; +/* A free list of CPLUS_BINDING nodes, connected by their + TREE_CHAINs. */ + +static tree free_bindings; /* Make DECL the innermost binding for ID. The LEVEL is the binding level at which this declaration is being bound. */ @@ -1091,22 +941,13 @@ push_binding (id, decl, level) { tree binding; - if (!free_binding_nodes) + if (free_bindings) { - /* There are no free nodes, so we must build one here. */ - push_obstacks_nochange (); - end_temporary_allocation (); - binding = make_node (CPLUS_BINDING); - pop_obstacks (); + binding = free_bindings; + free_bindings = TREE_CHAIN (binding); } else - { - /* There are nodes on the free list. Grab the first one. */ - binding = free_binding_nodes; - - /* And update the free list. */ - free_binding_nodes = TREE_CHAIN (free_binding_nodes); - } + binding = make_node (CPLUS_BINDING); /* Now, fill in the binding information. */ BINDING_VALUE (binding) = decl; @@ -1114,6 +955,7 @@ push_binding (id, decl, level) BINDING_LEVEL (binding) = level; INHERITED_VALUE_BINDING_P (binding) = 0; LOCAL_BINDING_P (binding) = (level != class_binding_level); + BINDING_HAS_LEVEL_P (binding) = 1; /* And put it on the front of the list of bindings for ID. */ TREE_CHAIN (binding) = IDENTIFIER_BINDING (id); @@ -1154,9 +996,37 @@ add_binding (id, decl) BINDING_VALUE (binding) = decl; INHERITED_VALUE_BINDING_P (binding) = 0; } + else if (TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL + && TREE_CODE (decl) == TYPE_DECL + && DECL_NAME (decl) == DECL_NAME (BINDING_VALUE (binding)) + && (same_type_p (TREE_TYPE (decl), + TREE_TYPE (BINDING_VALUE (binding))) + /* If either type involves template parameters, we must + wait until instantiation. */ + || uses_template_parms (TREE_TYPE (decl)) + || uses_template_parms (TREE_TYPE (BINDING_VALUE (binding))))) + /* We have two typedef-names, both naming the same type to have + the same name. This is OK because of: + + [dcl.typedef] + + In a given scope, a typedef specifier can be used to redefine + the name of any type declared in that scope to refer to the + type to which it already refers. */ + ok = 0; + /* There can be two block-scope declarations of the same variable, + so long as they are `extern' declarations. */ + else if (TREE_CODE (decl) == VAR_DECL + && TREE_CODE (BINDING_VALUE (binding)) == VAR_DECL + && DECL_EXTERNAL (decl) + && DECL_EXTERNAL (BINDING_VALUE (binding))) + { + duplicate_decls (decl, BINDING_VALUE (binding)); + ok = 0; + } else { - cp_error ("declaration of `%#D'", decl); + error ("declaration of `%#D'", decl); cp_error_at ("conflicts with previous declaration `%#D'", BINDING_VALUE (binding)); ok = 0; @@ -1165,9 +1035,23 @@ add_binding (id, decl) return ok; } -/* Bind DECL to ID in the current_binding_level. - If PUSH_USING is set in FLAGS, we know that DECL doesn't really belong - to this binding level, that it got here through a using-declaration. */ +/* Add DECL to the list of things declared in B. */ + +static void +add_decl_to_level (decl, b) + tree decl; + struct binding_level *b; +{ + /* We build up the list in reverse order, and reverse it later if + necessary. */ + TREE_CHAIN (decl) = b->names; + b->names = decl; +} + +/* Bind DECL to ID in the current_binding_level, assumed to be a local + binding level. If PUSH_USING is set in FLAGS, we know that DECL + doesn't really belong to this binding level, that it got here + through a using-declaration. */ void push_local_binding (id, decl, flags) @@ -1204,8 +1088,7 @@ push_local_binding (id, decl, flags) /* And put DECL on the list of things declared by the current binding level. */ - TREE_CHAIN (decl) = b->names; - b->names = decl; + add_decl_to_level (decl, b); } /* Bind DECL to ID in the class_binding_level. Returns nonzero if the @@ -1247,18 +1130,16 @@ push_class_binding (id, decl) context for an implicit typename declaration is always the derived class in which the lookup was done, so the checks based on the context of DECL below will not trigger. */ - if (TREE_CODE (decl) == TYPE_DECL - && IMPLICIT_TYPENAME_P (TREE_TYPE (decl))) + if (IMPLICIT_TYPENAME_TYPE_DECL_P (decl)) INHERITED_VALUE_BINDING_P (binding) = 1; else { if (TREE_CODE (decl) == OVERLOAD) - context = DECL_REAL_CONTEXT (OVL_CURRENT (decl)); + context = CP_DECL_CONTEXT (OVL_CURRENT (decl)); else { - my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd', - 0); - context = DECL_REAL_CONTEXT (decl); + my_friendly_assert (DECL_P (decl), 0); + context = context_for_name_lookup (decl); } if (is_properly_derived_from (current_class_type, context)) @@ -1279,13 +1160,13 @@ push_class_binding (id, decl) /* Remove the binding for DECL which should be the innermost binding for ID. */ -static void -pop_binding (id, decl) +static void +pop_binding (id, decl) tree id; tree decl; { tree binding; - + if (id == NULL_TREE) /* It's easiest to write the loops that call this function without checking whether or not the entities involved have names. We @@ -1305,7 +1186,7 @@ pop_binding (id, decl) else if (BINDING_TYPE (binding) == decl) BINDING_TYPE (binding) = NULL_TREE; else - my_friendly_abort (0); + abort (); if (!BINDING_VALUE (binding) && !BINDING_TYPE (binding)) { @@ -1313,10 +1194,61 @@ pop_binding (id, decl) identifier. Unhook it from the list of bindings. */ IDENTIFIER_BINDING (id) = TREE_CHAIN (binding); - /* And place it on the free list. */ - TREE_CHAIN (binding) = free_binding_nodes; - free_binding_nodes = binding; + /* Add it to the free list. */ + TREE_CHAIN (binding) = free_bindings; + free_bindings = binding; + + /* Clear the BINDING_LEVEL so the garbage collector doesn't walk + it. */ + BINDING_LEVEL (binding) = NULL; + } +} + +/* When a label goes out of scope, check to see if that label was used + in a valid manner, and issue any appropriate warnings or errors. */ + +static void +pop_label (label, old_value) + tree label; + tree old_value; +{ + if (!processing_template_decl && doing_semantic_analysis_p ()) + { + if (DECL_INITIAL (label) == NULL_TREE) + { + cp_error_at ("label `%D' used but not defined", label); + /* Avoid crashing later. */ + define_label (input_filename, 1, DECL_NAME (label)); + } + else if (warn_unused_label && !TREE_USED (label)) + cp_warning_at ("label `%D' defined but not used", label); + } + + SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), old_value); +} + +/* At the end of a function, all labels declared within the function + go out of scope. BLOCK is the top-level block for the + function. */ + +static void +pop_labels (block) + tree block; +{ + struct named_label_list *link; + + /* Clear out the definitions of all label names, since their scopes + end here. */ + for (link = named_labels; link; link = link->next) + { + pop_label (link->label_decl, link->old_value); + /* Put the labels into the "variables" of the top-level block, + so debugger can see them. */ + TREE_CHAIN (link->label_decl) = BLOCK_VARS (block); + BLOCK_VARS (block) = link->label_decl; } + + named_labels = NULL; } /* Exit a binding level. @@ -1345,17 +1277,23 @@ poplevel (keep, reverse, functionbody) Put it into forward order, just for cleanliness. */ tree decls; int tmp = functionbody; - int real_functionbody = current_binding_level->keep == 2 - ? ((functionbody = 0), tmp) : functionbody; - tree tags = functionbody >= 0 ? current_binding_level->tags : 0; - tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; + int real_functionbody; + tree tags; + tree subblocks; tree block = NULL_TREE; tree decl; - int block_previously_created; int leaving_for_scope; - if (current_binding_level->parm_flag == 2) - return poplevel_class (); + if (cfun && !doing_semantic_analysis_p ()) + return NULL_TREE; + + my_friendly_assert (current_binding_level->parm_flag != 2, + 19990916); + + real_functionbody = (current_binding_level->keep == 2 + ? ((functionbody = 0), tmp) : functionbody); + tags = functionbody >= 0 ? current_binding_level->tags : 0; + subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; my_friendly_assert (!current_binding_level->class_shadowed, 19990414); @@ -1365,14 +1303,50 @@ poplevel (keep, reverse, functionbody) rather than the end. This hack is no longer used. */ my_friendly_assert (keep == 0 || keep == 1, 0); - GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, - (HOST_WIDE_INT) current_binding_level->level_chain, + GNU_xref_end_scope ((size_t) current_binding_level, + (size_t) current_binding_level->level_chain, current_binding_level->parm_flag, current_binding_level->keep); if (current_binding_level->keep == 1) keep = 1; + /* Any uses of undefined labels, and any defined labels, now operate + under constraints of next binding contour. */ + if (cfun && !functionbody) + { + struct binding_level *level_chain; + level_chain = current_binding_level->level_chain; + if (level_chain) + { + struct named_label_use_list *uses; + struct named_label_list *labels; + for (labels = named_labels; labels; labels = labels->next) + if (labels->binding_level == current_binding_level) + { + tree decl; + if (current_binding_level->is_try_scope) + labels->in_try_scope = 1; + if (current_binding_level->is_catch_scope) + labels->in_catch_scope = 1; + for (decl = labels->names_in_scope; decl; + decl = TREE_CHAIN (decl)) + if (decl_jump_unsafe (decl)) + labels->bad_decls = tree_cons (NULL_TREE, decl, + labels->bad_decls); + labels->binding_level = level_chain; + labels->names_in_scope = level_chain->names; + } + + for (uses = named_label_uses; uses; uses = uses->next) + if (uses->binding_level == current_binding_level) + { + uses->binding_level = level_chain; + uses->names_in_scope = level_chain->names; + } + } + } + /* Get the decls in the order they were written. Usually current_binding_level->names is in reverse order. But parameter decls were previously put in forward order. */ @@ -1385,7 +1359,6 @@ poplevel (keep, reverse, functionbody) /* Output any nested inline functions within this block if they weren't already output. */ - for (decl = decls; decl; decl = TREE_CHAIN (decl)) if (TREE_CODE (decl) == FUNCTION_DECL && ! TREE_ASM_WRITTEN (decl) @@ -1406,51 +1379,27 @@ poplevel (keep, reverse, functionbody) } } + /* When not in function-at-a-time mode, expand_end_bindings will + warn about unused variables. But, in function-at-a-time mode + expand_end_bindings is not passed the list of variables in the + current scope, and therefore no warning is emitted. So, we + explicitly warn here. */ + if (!processing_template_decl) + warn_about_unused_variables (getdecls ()); + /* If there were any declarations or structure tags in that level, or if this level is a function body, create a BLOCK to record them for the life of this function. */ - block = NULL_TREE; - block_previously_created = (current_binding_level->this_block != NULL_TREE); - if (block_previously_created) - block = current_binding_level->this_block; - else if (keep == 1 || functionbody) + if (keep == 1 || functionbody) block = make_node (BLOCK); if (block != NULL_TREE) { - if (block_previously_created) - { - if (decls || tags || subblocks) - { - if (BLOCK_VARS (block) || BLOCK_TYPE_TAGS (block)) - warning ("internal compiler error: debugging info corrupted"); - - BLOCK_VARS (block) = decls; - BLOCK_TYPE_TAGS (block) = tags; - - /* We can have previous subblocks and new subblocks when - doing fixup_gotos with complex cleanups. We chain the new - subblocks onto the end of any pre-existing subblocks. */ - BLOCK_SUBBLOCKS (block) = chainon (BLOCK_SUBBLOCKS (block), - subblocks); - } - /* If we created the block earlier on, and we are just - diddling it now, then it already should have a proper - BLOCK_END_NOTE value associated with it. */ - } - else - { - BLOCK_VARS (block) = decls; - BLOCK_TYPE_TAGS (block) = tags; - BLOCK_SUBBLOCKS (block) = subblocks; - /* Otherwise, for a new block, install a new BLOCK_END_NOTE - value. */ - remember_end_note (block); - } + BLOCK_VARS (block) = decls; + BLOCK_SUBBLOCKS (block) = subblocks; } /* In each subblock, record that this is its superior. */ - if (keep >= 0) for (link = subblocks; link; link = TREE_CHAIN (link)) BLOCK_SUPERCONTEXT (link) = block; @@ -1459,15 +1408,16 @@ poplevel (keep, reverse, functionbody) in a for-init statement were in scope after the for-statement ended. We only use the new rules in flag_new_for_scope is nonzero. */ - leaving_for_scope + leaving_for_scope = current_binding_level->is_for_scope && flag_new_for_scope == 1; /* Remove declarations for all the DECLs in this level. */ for (link = decls; link; link = TREE_CHAIN (link)) { - if (leaving_for_scope && TREE_CODE (link) == VAR_DECL) + if (leaving_for_scope && TREE_CODE (link) == VAR_DECL + && DECL_NAME (link)) { - tree outer_binding + tree outer_binding = TREE_CHAIN (IDENTIFIER_BINDING (DECL_NAME (link))); tree ns_binding; @@ -1476,21 +1426,21 @@ poplevel (keep, reverse, functionbody) else ns_binding = NULL_TREE; - if (outer_binding - && (BINDING_LEVEL (outer_binding) + if (outer_binding + && (BINDING_LEVEL (outer_binding) == current_binding_level->level_chain)) /* We have something like: - + int i; for (int i; ;); - + and we are leaving the `for' scope. There's no reason to keep the binding of the inner `i' in this case. */ pop_binding (DECL_NAME (link), link); - else if ((outer_binding - && (TREE_CODE (BINDING_VALUE (outer_binding)) + else if ((outer_binding + && (TREE_CODE (BINDING_VALUE (outer_binding)) == TYPE_DECL)) - || (ns_binding + || (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL)) /* Here, we have something like: @@ -1508,11 +1458,11 @@ poplevel (keep, reverse, functionbody) /* Mark this VAR_DECL as dead so that we can tell we left it there only for backward compatibility. */ DECL_DEAD_FOR_LOCAL (link) = 1; - + /* Keep track of what should of have happenned when we popped the binding. */ if (outer_binding && BINDING_VALUE (outer_binding)) - DECL_SHADOWED_FOR_VAR (link) + DECL_SHADOWED_FOR_VAR (link) = BINDING_VALUE (outer_binding); /* Add it to the list of dead variables in the next @@ -1529,18 +1479,18 @@ poplevel (keep, reverse, functionbody) = 0; } } - else + else { /* Remove the binding. */ decl = link; if (TREE_CODE (decl) == TREE_LIST) decl = TREE_VALUE (decl); - if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd') + if (DECL_P (decl)) pop_binding (DECL_NAME (decl), decl); else if (TREE_CODE (decl) == OVERLOAD) pop_binding (DECL_NAME (OVL_FUNCTION (decl)), decl); - else - my_friendly_abort (0); + else + abort (); } } @@ -1554,7 +1504,13 @@ poplevel (keep, reverse, functionbody) for (link = current_binding_level->type_shadowed; link; link = TREE_CHAIN (link)) SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link)); - + + /* Restore the IDENTIFIER_LABEL_VALUEs for local labels. */ + for (link = current_binding_level->shadowed_labels; + link; + link = TREE_CHAIN (link)) + pop_label (TREE_VALUE (link), TREE_PURPOSE (link)); + /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs list if a `using' declaration put them there. The debugging back-ends won't understand OVERLOAD, so we remove them here. @@ -1576,70 +1532,24 @@ poplevel (keep, reverse, functionbody) /* If the level being exited is the top level of a function, check over all the labels. */ - if (functionbody) { - /* If this is the top level block of a function, - the vars are the function's parameters. - Don't leave them in the BLOCK because they are - found in the FUNCTION_DECL instead. */ - + /* Since this is the top level block of a function, the vars are + the function's parameters. Don't leave them in the BLOCK + because they are found in the FUNCTION_DECL instead. */ BLOCK_VARS (block) = 0; - - /* Clear out the definitions of all label names, - since their scopes end here. */ - - for (link = named_labels; link; link = TREE_CHAIN (link)) - { - register tree label = TREE_VALUE (link); - - if (DECL_INITIAL (label) == NULL_TREE) - { - cp_error_at ("label `%D' used but not defined", label); - /* Avoid crashing later. */ - define_label (input_filename, 1, DECL_NAME (label)); - } - else if (warn_unused && !TREE_USED (label)) - cp_warning_at ("label `%D' defined but not used", label); - SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE); - - /* Put the labels into the "variables" of the - top-level block, so debugger can see them. */ - TREE_CHAIN (label) = BLOCK_VARS (block); - BLOCK_VARS (block) = label; - } - - named_labels = NULL_TREE; + pop_labels (block); } - /* Any uses of undefined labels now operate under constraints - of next binding contour. */ - { - struct binding_level *level_chain; - level_chain = current_binding_level->level_chain; - if (level_chain) - { - struct named_label_list *labels; - for (labels = named_label_uses; labels; labels = labels->next) - if (labels->binding_level == current_binding_level) - { - labels->binding_level = level_chain; - labels->names_in_scope = level_chain->names; - } - } - } - tmp = current_binding_level->keep; pop_binding_level (); if (functionbody) DECL_INITIAL (current_function_decl) = block; else if (block) - { - if (!block_previously_created) - current_binding_level->blocks - = chainon (current_binding_level->blocks, block); - } + current_binding_level->blocks + = chainon (current_binding_level->blocks, block); + /* If we did not make a block for the level just exited, any blocks made for inner levels (since they cannot be recorded as subblocks in that level) @@ -1649,23 +1559,28 @@ poplevel (keep, reverse, functionbody) current_binding_level->blocks = chainon (current_binding_level->blocks, subblocks); + /* Each and every BLOCK node created here in `poplevel' is important + (e.g. for proper debugging information) so if we created one + earlier, mark it as "used". */ + if (block) + TREE_USED (block) = 1; + /* Take care of compiler's internal binding structures. */ if (tmp == 2) { - expand_end_bindings (getdecls (), keep, 1); - /* Each and every BLOCK node created here in `poplevel' is important - (e.g. for proper debugging information) so if we created one - earlier, mark it as "used". */ + tree scope_stmts; + + scope_stmts + = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/1); if (block) - TREE_USED (block) = 1; - block = poplevel (keep, reverse, real_functionbody); + { + SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block; + SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block; + } + + block = poplevel (keep, reverse, functionbody); } - /* Each and every BLOCK node created here in `poplevel' is important - (e.g. for proper debugging information) so if we created one - earlier, mark it as "used". */ - if (block) - TREE_USED (block) = 1; return block; } @@ -1711,9 +1626,11 @@ insert_block (block) void set_block (block) - register tree block; + tree block ATTRIBUTE_UNUSED; { - current_binding_level->this_block = block; + /* The RTL expansion machinery requires us to provide this callback, + but it is not applicable in function-at-a-time mode. */ + my_friendly_assert (cfun && !doing_semantic_analysis_p (), 20000911); } /* Do a pushlevel for class declarations. */ @@ -1742,22 +1659,21 @@ pushlevel_class () push_binding_level (newlevel, 0, 0); - decl_stack = push_decl_level (decl_stack, &decl_obstack); class_binding_level = current_binding_level; class_binding_level->parm_flag = 2; + class_binding_level->this_class = current_class_type; } /* ...and a poplevel for class declarations. */ -static tree +void poplevel_class () { register struct binding_level *level = class_binding_level; tree shadowed; my_friendly_assert (level != 0, 354); - - decl_stack = pop_stack_level (decl_stack); + /* If we're leaving a toplevel class, don't bother to do the setting of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot shouldn't even be used when current_class_type isn't set, and second, @@ -1772,7 +1688,7 @@ poplevel_class () shadowed; shadowed = TREE_CHAIN (shadowed)) IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = NULL_TREE; - + /* Find the next enclosing class, and recreate IDENTIFIER_CLASS_VALUEs appropriate for that class. */ b = level->level_chain; @@ -1780,8 +1696,8 @@ poplevel_class () b = b->level_chain; if (b) - for (shadowed = b->class_shadowed; - shadowed; + for (shadowed = b->class_shadowed; + shadowed; shadowed = TREE_CHAIN (shadowed)) { tree t; @@ -1789,9 +1705,9 @@ poplevel_class () t = IDENTIFIER_BINDING (TREE_PURPOSE (shadowed)); while (t && BINDING_LEVEL (t) != b) t = TREE_CHAIN (t); - + if (t) - IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) + IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = BINDING_VALUE (t); } } @@ -1808,13 +1724,13 @@ poplevel_class () SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed), TREE_VALUE (shadowed)); /* Remove the bindings for all of the class-level declarations. */ - for (shadowed = level->class_shadowed; - shadowed; + for (shadowed = level->class_shadowed; + shadowed; shadowed = TREE_CHAIN (shadowed)) pop_binding (TREE_PURPOSE (shadowed), TREE_TYPE (shadowed)); - GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, - (HOST_WIDE_INT) class_binding_level->level_chain, + GNU_xref_end_scope ((size_t) class_binding_level, + (size_t) class_binding_level->level_chain, class_binding_level->parm_flag, class_binding_level->keep); @@ -1825,8 +1741,6 @@ poplevel_class () #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ pop_binding_level (); - - return NULL_TREE; } /* We are entering the scope of a class. Clear IDENTIFIER_CLASS_VALUE @@ -1865,21 +1779,17 @@ vtype_decl_p (t, data) void *data ATTRIBUTE_UNUSED; { return (TREE_CODE (t) == TYPE_DECL - && TREE_TYPE (t) != error_mark_node - && TYPE_LANG_SPECIFIC (TREE_TYPE (t)) - && CLASSTYPE_VSIZE (TREE_TYPE (t))); + && TREE_CODE (TREE_TYPE (t)) == RECORD_TYPE + && TYPE_POLYMORPHIC_P (TREE_TYPE (t))); } -/* Returns non-zero if T is a signature table. */ +/* Return the declarations that are members of the namespace NS. */ -int -sigtable_decl_p (t, data) - tree t; - void *data ATTRIBUTE_UNUSED; +tree +cp_namespace_decls (ns) + tree ns; { - return (TREE_CODE (t) == VAR_DECL - && TREE_TYPE (t) != error_mark_node - && IS_SIGNATURE (TREE_TYPE (t))); + return NAMESPACE_LEVEL (ns)->names; } /* Walk all the namespaces contained NAMESPACE, including NAMESPACE @@ -1896,19 +1806,13 @@ walk_namespaces_r (namespace, f, data) result |= (*f) (namespace, data); - for (current = NAMESPACE_LEVEL (namespace)->names; + for (current = cp_namespace_decls (namespace); current; current = TREE_CHAIN (current)) { if (TREE_CODE (current) != NAMESPACE_DECL || DECL_NAMESPACE_ALIAS (current)) continue; - if (!DECL_LANG_SPECIFIC (current)) - { - /* Hmm. std. */ - my_friendly_assert (current == std_node, 393); - continue; - } /* We found a namespace. */ result |= walk_namespaces_r (current, f, data); @@ -1938,7 +1842,7 @@ struct walk_globals_data { for which P returns non-zero, call F with its address. If any call to F returns a non-zero value, return a non-zero value. */ -static int +static int walk_globals_r (namespace, data) tree namespace; void *data; @@ -1995,7 +1899,7 @@ wrapup_globals_for_namespace (namespace, data) tree namespace; void *data; { - tree globals = NAMESPACE_LEVEL (namespace)->names; + tree globals = cp_namespace_decls (namespace); int len = list_length (globals); tree *vec = (tree *) alloca (sizeof (tree) * len); int i; @@ -2009,10 +1913,9 @@ wrapup_globals_for_namespace (namespace, data) /* Process the decls in reverse order--earliest first. Put them into VEC from back to front, then take out from front. */ - for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl)) vec[len - i - 1] = decl; - + if (last_time) { check_global_declarations (vec, len); @@ -2045,6 +1948,51 @@ wrapup_globals_for_namespace (namespace, data) } +/* Mark ARG (which is really a struct binding_level **) for GC. */ + +static void +mark_binding_level (arg) + void *arg; +{ + struct binding_level *lvl = *(struct binding_level **)arg; + + for (; lvl; lvl = lvl->level_chain) + { + ggc_mark_tree (lvl->names); + ggc_mark_tree (lvl->tags); + ggc_mark_tree (lvl->usings); + ggc_mark_tree (lvl->using_directives); + ggc_mark_tree (lvl->class_shadowed); + ggc_mark_tree (lvl->type_shadowed); + ggc_mark_tree (lvl->shadowed_labels); + ggc_mark_tree (lvl->blocks); + ggc_mark_tree (lvl->this_class); + ggc_mark_tree (lvl->incomplete); + ggc_mark_tree (lvl->dead_vars_from_for); + } +} + +static void +mark_named_label_lists (labs, uses) + void *labs; + void *uses; +{ + struct named_label_list *l = *(struct named_label_list **)labs; + struct named_label_use_list *u = *(struct named_label_use_list **)uses; + + for (; l; l = l->next) + { + ggc_mark (l); + mark_binding_level (l->binding_level); + ggc_mark_tree (l->old_value); + ggc_mark_tree (l->label_decl); + ggc_mark_tree (l->bad_decls); + } + + for (; u; u = u->next) + ggc_mark (u); +} + /* For debugging. */ static int no_print_functions = 0; static int no_print_builtins = 0; @@ -2072,7 +2020,7 @@ print_binding_level (lvl) /* We can probably fit 3 names to a line? */ for (t = lvl->names; t; t = TREE_CHAIN (t)) { - if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL)) + if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL)) continue; if (no_print_builtins && (TREE_CODE (t) == TYPE_DECL) @@ -2211,14 +2159,14 @@ find_binding (name, scope) tree iter, prev = NULL_TREE; scope = ORIGINAL_NAMESPACE (scope); - + for (iter = IDENTIFIER_NAMESPACE_BINDINGS (name); iter; iter = TREE_CHAIN (iter)) { my_friendly_assert (TREE_CODE (iter) == CPLUS_BINDING, 374); if (BINDING_SCOPE (iter) == scope) { - /* Move binding found to the fron of the list, so + /* Move binding found to the front of the list, so subsequent lookups will find it faster. */ if (prev) { @@ -2246,7 +2194,7 @@ binding_for_name (name, scope) tree result; scope = ORIGINAL_NAMESPACE (scope); - + if (b && TREE_CODE (b) != CPLUS_BINDING) { /* Get rid of optimization for global scope. */ @@ -2256,15 +2204,13 @@ binding_for_name (name, scope) } if (b && (result = find_binding (name, scope))) return result; - /* Not found, make a new permanent one. */ - push_obstacks (&permanent_obstack, &permanent_obstack); + /* Not found, make a new one. */ result = make_node (CPLUS_BINDING); TREE_CHAIN (result) = b; IDENTIFIER_NAMESPACE_BINDINGS (name) = result; BINDING_SCOPE (result) = scope; BINDING_TYPE (result) = NULL_TREE; BINDING_VALUE (result) = NULL_TREE; - pop_obstacks (); return result; } @@ -2302,7 +2248,7 @@ set_namespace_binding (name, scope, val) if (scope == NULL_TREE) scope = global_namespace; - + if (scope == global_namespace) { b = IDENTIFIER_NAMESPACE_BINDINGS (name); @@ -2346,12 +2292,6 @@ push_namespace (name) need_new = 0; implicit_use = 1; } - else if (current_namespace == global_namespace - && name == DECL_NAME (std_node)) - { - in_std++; - return; - } else { /* Check whether this is an extended namespace definition. */ @@ -2361,13 +2301,13 @@ push_namespace (name) need_new = 0; if (DECL_NAMESPACE_ALIAS (d)) { - cp_error ("namespace alias `%D' not allowed here, assuming `%D'", + error ("namespace alias `%D' not allowed here, assuming `%D'", d, DECL_NAMESPACE_ALIAS (d)); d = DECL_NAMESPACE_ALIAS (d); } } } - + if (need_new) { /* Make a new namespace, binding the name to it. */ @@ -2376,6 +2316,7 @@ push_namespace (name) level is set elsewhere. */ if (!global) { + DECL_CONTEXT (d) = FROB_CONTEXT (current_namespace); d = pushdecl (d); pushlevel (0); declare_namespace_level (); @@ -2396,55 +2337,92 @@ push_namespace (name) void pop_namespace () { - if (current_namespace == global_namespace) - { - my_friendly_assert (in_std>0, 980421); - in_std--; - return; - } + my_friendly_assert (current_namespace != global_namespace, 20010801); current_namespace = CP_DECL_CONTEXT (current_namespace); /* The binding level is not popped, as it might be re-opened later. */ suspend_binding_level (); } +/* Push into the scope of the namespace NS, even if it is deeply + nested within another namespace. */ + +void +push_nested_namespace (ns) + tree ns; +{ + if (ns == global_namespace) + push_to_top_level (); + else + { + push_nested_namespace (CP_DECL_CONTEXT (ns)); + push_namespace (DECL_NAME (ns)); + } +} + +/* Pop back from the scope of the namespace NS, which was previously + entered with push_nested_namespace. */ + +void +pop_nested_namespace (ns) + tree ns; +{ + while (ns != global_namespace) + { + pop_namespace (); + ns = CP_DECL_CONTEXT (ns); + } + + pop_from_top_level (); +} + /* Subroutines for reverting temporarily to top-level for instantiation of templates and such. We actually need to clear out the class- and local-value slots of all identifiers, so that only the global values are at all visible. Simply setting current_binding_level to the global scope isn't enough, because more binding levels may be pushed. */ -struct saved_scope { - struct binding_level *old_binding_level; - tree old_bindings; - tree old_namespace; - struct saved_scope *prev; - tree class_name, class_type; - tree access_specifier; - tree function_decl; - struct binding_level *class_bindings; - tree *lang_base, *lang_stack, lang_name; - int lang_stacksize; - int minimal_parse_mode; - tree last_function_parms; - tree template_parms; - HOST_WIDE_INT processing_template_decl; - tree previous_class_type, previous_class_values; - int processing_specialization; - int processing_explicit_instantiation; - char *class_cache_firstobj; -}; -static struct saved_scope *current_saved_scope; +struct saved_scope *scope_chain; -/* A chain of the binding vecs created by store_bindings. We create a - whole bunch of these during compilation, on permanent_obstack, so we - can't just throw them away. */ -static tree free_binding_vecs; +/* Mark ARG (which is really a struct saved_scope **) for GC. */ + +static void +mark_saved_scope (arg) + void *arg; +{ + struct saved_scope *t = *(struct saved_scope **)arg; + while (t) + { + mark_binding_level (&t->class_bindings); + ggc_mark_tree (t->old_bindings); + ggc_mark_tree (t->old_namespace); + ggc_mark_tree (t->decl_ns_list); + ggc_mark_tree (t->class_name); + ggc_mark_tree (t->class_type); + ggc_mark_tree (t->access_specifier); + ggc_mark_tree (t->function_decl); + if (t->lang_base) + ggc_mark_tree_varray (t->lang_base); + ggc_mark_tree (t->lang_name); + ggc_mark_tree (t->template_parms); + ggc_mark_tree (t->x_previous_class_type); + ggc_mark_tree (t->x_previous_class_values); + ggc_mark_tree (t->x_saved_tree); + ggc_mark_tree (t->incomplete); + ggc_mark_tree (t->lookups); + + mark_stmt_tree (&t->x_stmt_tree); + mark_binding_level (&t->bindings); + t = t->prev; + } +} static tree store_bindings (names, old_bindings) tree names, old_bindings; { tree t; + tree search_bindings = old_bindings; + for (t = names; t; t = TREE_CHAIN (t)) { tree binding, t1, id; @@ -2454,35 +2432,25 @@ store_bindings (names, old_bindings) else id = DECL_NAME (t); - if (!id + if (!id /* Note that we may have an IDENTIFIER_CLASS_VALUE even when we have no IDENTIFIER_BINDING if we have left the class scope, but cached the class-level declarations. */ || !(IDENTIFIER_BINDING (id) || IDENTIFIER_CLASS_VALUE (id))) continue; - for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) + for (t1 = search_bindings; t1; t1 = TREE_CHAIN (t1)) if (TREE_VEC_ELT (t1, 0) == id) goto skip_it; - if (free_binding_vecs) - { - binding = free_binding_vecs; - free_binding_vecs = TREE_CHAIN (free_binding_vecs); - } - else - binding = make_tree_vec (4); - - if (id) - { - my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); - TREE_VEC_ELT (binding, 0) = id; - TREE_VEC_ELT (binding, 1) = REAL_IDENTIFIER_TYPE_VALUE (id); - TREE_VEC_ELT (binding, 2) = IDENTIFIER_BINDING (id); - TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); - IDENTIFIER_BINDING (id) = NULL_TREE; - IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; - } + my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); + binding = make_tree_vec (4); + TREE_VEC_ELT (binding, 0) = id; + TREE_VEC_ELT (binding, 1) = REAL_IDENTIFIER_TYPE_VALUE (id); + TREE_VEC_ELT (binding, 2) = IDENTIFIER_BINDING (id); + TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); + IDENTIFIER_BINDING (id) = NULL_TREE; + IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; TREE_CHAIN (binding) = old_bindings; old_bindings = binding; skip_it: @@ -2495,15 +2463,26 @@ void maybe_push_to_top_level (pseudo) int pseudo; { - extern int current_lang_stacksize; - struct saved_scope *s - = (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); - struct binding_level *b = current_binding_level; - tree old_bindings = NULL_TREE; + struct saved_scope *s; + struct binding_level *b; + tree old_bindings; + int need_pop; - push_cp_function_context (NULL_TREE); + s = (struct saved_scope *) xcalloc (1, sizeof (struct saved_scope)); - if (previous_class_type) + b = scope_chain ? current_binding_level : 0; + + /* If we're in the middle of some function, save our state. */ + if (cfun) + { + need_pop = 1; + push_function_context_to (NULL_TREE); + } + else + need_pop = 0; + + old_bindings = NULL_TREE; + if (scope_chain && previous_class_type) old_bindings = store_bindings (previous_class_values, old_bindings); /* Have to include global_binding_level, because class-level decls @@ -2516,7 +2495,7 @@ maybe_push_to_top_level (pseudo) inserted into namespace level, finish_file wouldn't find them when doing pending instantiations. Therefore, don't stop at namespace level, but continue until :: . */ - if (b == global_binding_level || (pseudo && b->pseudo_global)) + if (b == global_binding_level || (pseudo && b->template_parms_p)) break; old_bindings = store_bindings (b->names, old_bindings); @@ -2529,54 +2508,17 @@ maybe_push_to_top_level (pseudo) for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); } - - s->old_binding_level = current_binding_level; - current_binding_level = b; - - s->old_namespace = current_namespace; - s->class_name = current_class_name; - s->class_type = current_class_type; - s->access_specifier = current_access_specifier; + s->prev = scope_chain; + s->old_bindings = old_bindings; + s->bindings = b; + s->need_pop_function_context = need_pop; s->function_decl = current_function_decl; - s->class_bindings = class_binding_level; - s->lang_stack = current_lang_stack; - s->lang_base = current_lang_base; - s->lang_stacksize = current_lang_stacksize; - s->lang_name = current_lang_name; - s->minimal_parse_mode = minimal_parse_mode; - s->last_function_parms = last_function_parms; - s->template_parms = current_template_parms; - s->processing_template_decl = processing_template_decl; - s->previous_class_type = previous_class_type; - s->previous_class_values = previous_class_values; - s->class_cache_firstobj = class_cache_firstobj; - s->processing_specialization = processing_specialization; - s->processing_explicit_instantiation = processing_explicit_instantiation; - - current_class_name = current_class_type = NULL_TREE; + + scope_chain = s; current_function_decl = NULL_TREE; - class_binding_level = (struct binding_level *)0; - current_lang_stacksize = 10; - current_lang_stack = current_lang_base - = (tree *) xmalloc (current_lang_stacksize * sizeof (tree)); + VARRAY_TREE_INIT (current_lang_base, 10, "current_lang_base"); current_lang_name = lang_name_cplusplus; - strict_prototype = strict_prototypes_lang_cplusplus; - named_labels = NULL_TREE; - shadowed_labels = NULL_TREE; - minimal_parse_mode = 0; - previous_class_type = previous_class_values = NULL_TREE; - class_cache_firstobj = 0; - processing_specialization = 0; - processing_explicit_instantiation = 0; - current_template_parms = NULL_TREE; - processing_template_decl = 0; current_namespace = global_namespace; - - s->prev = current_saved_scope; - s->old_bindings = old_bindings; - current_saved_scope = s; - - push_obstacks (&permanent_obstack, &permanent_obstack); } void @@ -2588,64 +2530,36 @@ push_to_top_level () void pop_from_top_level () { - extern int current_lang_stacksize; - struct saved_scope *s = current_saved_scope; + struct saved_scope *s = scope_chain; tree t; /* Clear out class-level bindings cache. */ if (previous_class_type) invalidate_class_lookup_cache (); - pop_obstacks (); + VARRAY_FREE (current_lang_base); - current_binding_level = s->old_binding_level; - current_saved_scope = s->prev; - for (t = s->old_bindings; t; ) + scope_chain = s->prev; + for (t = s->old_bindings; t; t = TREE_CHAIN (t)) { - tree save = t; tree id = TREE_VEC_ELT (t, 0); - if (id) - { - SET_IDENTIFIER_TYPE_VALUE (id, TREE_VEC_ELT (t, 1)); - IDENTIFIER_BINDING (id) = TREE_VEC_ELT (t, 2); - IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); - } - t = TREE_CHAIN (t); - TREE_CHAIN (save) = free_binding_vecs; - free_binding_vecs = save; + + SET_IDENTIFIER_TYPE_VALUE (id, TREE_VEC_ELT (t, 1)); + IDENTIFIER_BINDING (id) = TREE_VEC_ELT (t, 2); + IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); } - current_namespace = s->old_namespace; - current_class_name = s->class_name; - current_class_type = s->class_type; - current_access_specifier = s->access_specifier; + + /* If we were in the middle of compiling a function, restore our + state. */ + if (s->need_pop_function_context) + pop_function_context_from (NULL_TREE); current_function_decl = s->function_decl; - class_binding_level = s->class_bindings; - free (current_lang_base); - current_lang_base = s->lang_base; - current_lang_stack = s->lang_stack; - current_lang_name = s->lang_name; - current_lang_stacksize = s->lang_stacksize; - if (current_lang_name == lang_name_cplusplus) - strict_prototype = strict_prototypes_lang_cplusplus; - else if (current_lang_name == lang_name_c) - strict_prototype = strict_prototypes_lang_c; - minimal_parse_mode = s->minimal_parse_mode; - last_function_parms = s->last_function_parms; - current_template_parms = s->template_parms; - processing_template_decl = s->processing_template_decl; - previous_class_type = s->previous_class_type; - previous_class_values = s->previous_class_values; - processing_specialization = s->processing_specialization; - processing_explicit_instantiation = s->processing_explicit_instantiation; - class_cache_firstobj = s->class_cache_firstobj; free (s); - - pop_cp_function_context (NULL_TREE); } /* Push a definition of struct, union or enum tag "name". - into binding_level "b". "type" should be the type node, + into binding_level "b". "type" should be the type node, We assume that the tag "name" is not already defined. Note that the definition may really be just a forward reference. @@ -2742,49 +2656,31 @@ pop_everything () Returns the TYPE_DECL for TYPE, which may have been altered by this processing. */ -static tree +static tree maybe_process_template_type_declaration (type, globalize, b) tree type; int globalize; struct binding_level* b; { tree decl = TYPE_NAME (type); - + if (processing_template_parmlist) /* You can't declare a new template type in a template parameter list. But, you can declare a non-template type: - + template <class A*> struct S; - + is a forward-declaration of `A'. */ ; - else + else { maybe_check_template_type (type); - my_friendly_assert (IS_AGGR_TYPE (type) + my_friendly_assert (IS_AGGR_TYPE (type) || TREE_CODE (type) == ENUMERAL_TYPE, 0); - - - if (/* If !GLOBALIZE then we are looking at a definition. - It may not be a primary template. (For example, in: - - template <class T> - struct S1 { class S2 {}; } - - we have to push_template_decl for S2.) */ - (processing_template_decl && !globalize) - /* If we are declaring a friend template class, we will - have GLOBALIZE set, since something like: - - template <class T> - struct S1 { - template <class U> - friend class S2; - }; - - declares S2 to be at global scope. */ - || PROCESSING_REAL_TEMPLATE_DECL_P ()) + + + if (processing_template_decl) { /* This may change after the call to push_template_decl_real, but we want the original value. */ @@ -2799,16 +2695,16 @@ maybe_process_template_type_declaration (type, globalize, b) friend case, push_template_decl will already have put the friend into global scope, if appropriate. */ if (TREE_CODE (type) != ENUMERAL_TYPE - && !globalize && b->pseudo_global + && !globalize && b->template_parms_p && b->level_chain->parm_flag == 2) { finish_member_declaration (CLASSTYPE_TI_TEMPLATE (type)); /* Put this tag on the list of tags for the class, since that won't happen below because B is not the class binding level, but is instead the pseudo-global level. */ - b->level_chain->tags = - saveable_tree_cons (name, type, b->level_chain->tags); - if (TYPE_SIZE (current_class_type) == NULL_TREE) + b->level_chain->tags = + tree_cons (name, type, b->level_chain->tags); + if (!COMPLETE_TYPE_P (current_class_type)) CLASSTYPE_TAGS (current_class_type) = b->level_chain->tags; } } @@ -2817,6 +2713,64 @@ maybe_process_template_type_declaration (type, globalize, b) return decl; } +/* In C++, you don't have to write `struct S' to refer to `S'; you + can just use `S'. We accomplish this by creating a TYPE_DECL as + if the user had written `typedef struct S S'. Create and return + the TYPE_DECL for TYPE. */ + +tree +create_implicit_typedef (name, type) + tree name; + tree type; +{ + tree decl; + + decl = build_decl (TYPE_DECL, name, type); + DECL_ARTIFICIAL (decl) = 1; + /* There are other implicit type declarations, like the one *within* + a class that allows you to write `S::S'. We must distinguish + amongst these. */ + SET_DECL_IMPLICIT_TYPEDEF_P (decl); + TYPE_NAME (type) = decl; + + return decl; +} + +/* Remember a local name for name-mangling purposes. */ + +static void +push_local_name (decl) + tree decl; +{ + size_t i, nelts; + tree t, name; + + if (!local_names) + VARRAY_TREE_INIT (local_names, 8, "local_names"); + + name = DECL_NAME (decl); + + nelts = VARRAY_ACTIVE_SIZE (local_names); + for (i = 0; i < nelts; i++) + { + t = VARRAY_TREE (local_names, i); + if (DECL_NAME (t) == name) + { + if (!DECL_LANG_SPECIFIC (decl)) + retrofit_lang_decl (decl); + if (DECL_LANG_SPECIFIC (t)) + DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1; + else + DECL_DISCRIMINATOR (decl) = 1; + + VARRAY_TREE (local_names, i) = decl; + return; + } + } + + VARRAY_PUSH_TREE (local_names, decl); +} + /* Push a tag name NAME for struct/class/union/enum type TYPE. Normally put it into the inner-most non-tag-transparent scope, but if GLOBALIZE is true, put it in the inner-most non-class scope. @@ -2831,13 +2785,16 @@ pushtag (name, type, globalize) b = current_binding_level; while (b->tag_transparent - || (globalize && b->parm_flag == 2)) + || (b->parm_flag == 2 + && (globalize + /* We may be defining a new type in the initializer + of a static member variable. We allow this when + not pedantic, and it is particularly useful for + type punning via an anonymous union. */ + || COMPLETE_TYPE_P (b->this_class)))) b = b->level_chain; - if (toplevel_bindings_p ()) - b->tags = perm_tree_cons (name, type, b->tags); - else - b->tags = saveable_tree_cons (name, type, b->tags); + b->tags = tree_cons (name, type, b->tags); if (name) { @@ -2845,59 +2802,42 @@ pushtag (name, type, globalize) if (IDENTIFIER_TYPE_VALUE (name) != type) { register tree d = NULL_TREE; - int newdecl = 0, in_class = 0; - tree context; - tree c_decl = NULL_TREE; + int in_class = 0; + tree context = TYPE_CONTEXT (type); - context = type ? TYPE_CONTEXT (type) : NULL_TREE; if (! context) { tree cs = current_scope (); if (! globalize) context = cs; - else if (cs != NULL_TREE - && TREE_CODE_CLASS (TREE_CODE (cs)) == 't') + else if (cs != NULL_TREE && TYPE_P (cs)) /* When declaring a friend class of a local class, we want to inject the newly named class into the scope containing the local class, not the namespace scope. */ - context = hack_decl_function_context (get_type_decl (cs)); + context = decl_function_context (get_type_decl (cs)); } - if (context) - c_decl = TREE_CODE (context) == FUNCTION_DECL - ? context : TYPE_MAIN_DECL (context); - if (!context) context = current_namespace; - if ((b->pseudo_global && b->level_chain->parm_flag == 2) + if ((b->template_parms_p && b->level_chain->parm_flag == 2) || b->parm_flag == 2) in_class = 1; - else - d = lookup_nested_type (type, c_decl); - if (d == NULL_TREE) - { - newdecl = 1; - d = build_decl (TYPE_DECL, name, type); - if (current_lang_name == lang_name_java) - TYPE_FOR_JAVA (type) = 1; - SET_DECL_ARTIFICIAL (d); - if (! in_class) - set_identifier_type_value_with_scope (name, type, b); - } - else - d = TYPE_MAIN_DECL (d); + if (current_lang_name == lang_name_java) + TYPE_FOR_JAVA (type) = 1; - TYPE_NAME (type) = d; + d = create_implicit_typedef (name, type); DECL_CONTEXT (d) = FROB_CONTEXT (context); + if (! in_class) + set_identifier_type_value_with_scope (name, type, b); d = maybe_process_template_type_declaration (type, globalize, b); if (b->parm_flag == 2) { - if (newdecl && !PROCESSING_REAL_TEMPLATE_DECL_P ()) + if (!PROCESSING_REAL_TEMPLATE_DECL_P ()) /* Put this TYPE_DECL on the TYPE_FIELDS list for the class. But if it's a member template class, we want the TEMPLATE_DECL, not the TYPE_DECL, so this @@ -2909,21 +2849,25 @@ pushtag (name, type, globalize) else d = pushdecl_with_scope (d, b); - if (newdecl) - { - if (ANON_AGGRNAME_P (name)) - DECL_IGNORED_P (d) = 1; - - TYPE_CONTEXT (type) = DECL_CONTEXT (d); - DECL_ASSEMBLER_NAME (d) = DECL_NAME (d); - if (!uses_template_parms (type)) - DECL_ASSEMBLER_NAME (d) - = get_identifier (build_overload_name (type, 1, 1)); - } + /* FIXME what if it gets a name from typedef? */ + if (ANON_AGGRNAME_P (name)) + DECL_IGNORED_P (d) = 1; + + TYPE_CONTEXT (type) = DECL_CONTEXT (d); + + /* If this is a local class, keep track of it. We need this + information for name-mangling, and so that it is possible to find + all function definitions in a translation unit in a convenient + way. (It's otherwise tricky to find a member function definition + it's only pointed to from within a local class.) */ + if (TYPE_CONTEXT (type) + && TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL + && !processing_template_decl) + VARRAY_PUSH_TREE (local_classes, type); } if (b->parm_flag == 2) { - if (TYPE_SIZE (current_class_type) == NULL_TREE) + if (!COMPLETE_TYPE_P (current_class_type)) CLASSTYPE_TAGS (current_class_type) = b->tags; } } @@ -3021,49 +2965,41 @@ decls_match (newdecl, olddecl) tree p1 = TYPE_ARG_TYPES (f1); tree p2 = TYPE_ARG_TYPES (f2); - if (DECL_REAL_CONTEXT (newdecl) != DECL_REAL_CONTEXT (olddecl) - && ! (DECL_LANGUAGE (newdecl) == lang_c - && DECL_LANGUAGE (olddecl) == lang_c)) + if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl) + && ! (DECL_EXTERN_C_P (newdecl) + && DECL_EXTERN_C_P (olddecl))) return 0; - /* When we parse a static member function definition, - we put together a FUNCTION_DECL which thinks its type - is METHOD_TYPE. Change that to FUNCTION_TYPE, and - proceed. */ - if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl)) - revert_static_member_fn (&newdecl, &f1, &p1); - else if (TREE_CODE (f2) == METHOD_TYPE - && DECL_STATIC_FUNCTION_P (newdecl)) - revert_static_member_fn (&olddecl, &f2, &p2); - - /* Here we must take care of the case where new default - parameters are specified. Also, warn if an old - declaration becomes ambiguous because default - parameters may cause the two to be ambiguous. */ if (TREE_CODE (f1) != TREE_CODE (f2)) - { - if (TREE_CODE (f1) == OFFSET_TYPE) - cp_compiler_error ("`%D' redeclared as member function", newdecl); - else - cp_compiler_error ("`%D' redeclared as non-member function", newdecl); - return 0; - } + return 0; if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2))) { - if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c - && p2 == NULL_TREE) + if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl) + && (DECL_BUILT_IN (olddecl) +#ifndef NO_IMPLICIT_EXTERN_C + || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl)) + || (DECL_IN_SYSTEM_HEADER (olddecl) && !DECL_CLASS_SCOPE_P (olddecl)) +#endif + )) { types_match = self_promoting_args_p (p1); if (p1 == void_list_node) TREE_TYPE (newdecl) = TREE_TYPE (olddecl); } - else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c - && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE) +#ifndef NO_IMPLICIT_EXTERN_C + else if (p1 == NULL_TREE + && (DECL_EXTERN_C_P (olddecl) + && DECL_IN_SYSTEM_HEADER (olddecl) + && !DECL_CLASS_SCOPE_P (olddecl)) + && (DECL_EXTERN_C_P (newdecl) + && DECL_IN_SYSTEM_HEADER (newdecl) + && !DECL_CLASS_SCOPE_P (newdecl))) { types_match = self_promoting_args_p (p2); TREE_TYPE (newdecl) = TREE_TYPE (olddecl); } +#endif else types_match = compparms (p1, p2); } @@ -3075,7 +3011,11 @@ decls_match (newdecl, olddecl) if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), DECL_TEMPLATE_PARMS (olddecl))) return 0; - + + if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) + != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))) + return 0; + if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) types_match = 1; else @@ -3100,8 +3040,7 @@ decls_match (newdecl, olddecl) } /* If NEWDECL is `static' and an `extern' was seen previously, - warn about it. (OLDDECL may be NULL_TREE; NAME contains - information about previous usage as an `extern'.) + warn about it. OLDDECL is the previous declaration. Note that this does not apply to the C++ case of declaring a variable `extern const' and then later `const'. @@ -3113,34 +3052,39 @@ static void warn_extern_redeclared_static (newdecl, olddecl) tree newdecl, olddecl; { - tree name; - - static const char *explicit_extern_static_warning + static const char *const explicit_extern_static_warning = "`%D' was declared `extern' and later `static'"; - static const char *implicit_extern_static_warning + static const char *const implicit_extern_static_warning = "`%D' was declared implicitly `extern' and later `static'"; - if (TREE_CODE (newdecl) == TYPE_DECL) + tree name; + + if (TREE_CODE (newdecl) == TYPE_DECL + || TREE_CODE (newdecl) == TEMPLATE_DECL + || TREE_CODE (newdecl) == CONST_DECL) + return; + + /* Don't get confused by static member functions; that's a different + use of `static'. */ + if (TREE_CODE (newdecl) == FUNCTION_DECL + && DECL_STATIC_FUNCTION_P (newdecl)) + return; + + /* If the old declaration was `static', or the new one isn't, then + then everything is OK. */ + if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl)) + return; + + /* It's OK to declare a builtin function as `static'. */ + if (TREE_CODE (olddecl) == FUNCTION_DECL + && DECL_ARTIFICIAL (olddecl)) return; name = DECL_ASSEMBLER_NAME (newdecl); - if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl)) - { - /* It's okay to redeclare an ANSI built-in function as static, - or to declare a non-ANSI built-in function as anything. */ - if (! (TREE_CODE (newdecl) == FUNCTION_DECL - && olddecl != NULL_TREE - && TREE_CODE (olddecl) == FUNCTION_DECL - && (DECL_BUILT_IN (olddecl) - || DECL_BUILT_IN_NONANSI (olddecl)))) - { - cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name) - ? implicit_extern_static_warning - : explicit_extern_static_warning, newdecl); - if (olddecl != NULL_TREE) - cp_pedwarn_at ("previous declaration of `%D'", olddecl); - } - } + pedwarn (IDENTIFIER_IMPLICIT_DECL (name) + ? implicit_extern_static_warning + : explicit_extern_static_warning, newdecl); + cp_pedwarn_at ("previous declaration of `%D'", olddecl); } /* Handle when a new declaration NEWDECL has the same name as an old @@ -3154,7 +3098,6 @@ int duplicate_decls (newdecl, olddecl) tree newdecl, olddecl; { - extern struct obstack permanent_obstack; unsigned olddecl_uid = DECL_UID (olddecl); int olddecl_friend = 0, types_match = 0; int new_defines_function = 0; @@ -3172,47 +3115,111 @@ duplicate_decls (newdecl, olddecl) if (TREE_TYPE (newdecl) == error_mark_node || TREE_TYPE (olddecl) == error_mark_node) types_match = 1; - + + if (DECL_P (olddecl) + && TREE_CODE (newdecl) == FUNCTION_DECL + && TREE_CODE (olddecl) == FUNCTION_DECL + && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl))) + { + if (DECL_DECLARED_INLINE_P (newdecl) + && DECL_UNINLINABLE (newdecl) + && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) + /* Already warned elsewhere. */; + else if (DECL_DECLARED_INLINE_P (olddecl) + && DECL_UNINLINABLE (olddecl) + && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) + /* Already warned. */; + else if (DECL_DECLARED_INLINE_P (newdecl) + && DECL_UNINLINABLE (olddecl) + && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) + { + warning_with_decl (newdecl, + "function `%s' redeclared as inline"); + warning_with_decl (olddecl, + "previous declaration of function `%s' with attribute noinline"); + } + else if (DECL_DECLARED_INLINE_P (olddecl) + && DECL_UNINLINABLE (newdecl) + && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) + { + warning_with_decl (newdecl, + "function `%s' redeclared with attribute noinline"); + warning_with_decl (olddecl, + "previous declaration of function `%s' was inline"); + } + } + /* Check for redeclaration and other discrepancies. */ if (TREE_CODE (olddecl) == FUNCTION_DECL - && DECL_ARTIFICIAL (olddecl) - && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl))) - { - /* If you declare a built-in or predefined function name as static, - the old definition is overridden, but optionally warn this was a - bad choice of name. Ditto for overloads. */ - if (! TREE_PUBLIC (newdecl) - || (TREE_CODE (newdecl) == FUNCTION_DECL - && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))) - { - if (warn_shadow) - cp_warning ("shadowing %s function `%#D'", - DECL_BUILT_IN (olddecl) ? "built-in" : "library", + && DECL_ARTIFICIAL (olddecl)) + { + if (TREE_CODE (newdecl) != FUNCTION_DECL) + { + /* If you declare a built-in or predefined function name as static, + the old definition is overridden, but optionally warn this was a + bad choice of name. */ + if (! TREE_PUBLIC (newdecl)) + { + if (warn_shadow) + warning ("shadowing %s function `%#D'", + DECL_BUILT_IN (olddecl) ? "built-in" : "library", + olddecl); + /* Discard the old built-in function. */ + return 0; + } + /* If the built-in is not ansi, then programs can override + it even globally without an error. */ + else if (! DECL_BUILT_IN (olddecl)) + warning ("library function `%#D' redeclared as non-function `%#D'", + olddecl, newdecl); + else + { + error ("declaration of `%#D'", newdecl); + error ("conflicts with built-in declaration `%#D'", olddecl); - /* Discard the old built-in function. */ + } return 0; } - else if (! types_match) + else if (!types_match) { - if (TREE_CODE (newdecl) != FUNCTION_DECL) + if ((DECL_EXTERN_C_P (newdecl) + && DECL_EXTERN_C_P (olddecl)) + || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)), + TYPE_ARG_TYPES (TREE_TYPE (olddecl)))) { - /* If the built-in is not ansi, then programs can override - it even globally without an error. */ - if (! DECL_BUILT_IN (olddecl)) - cp_warning ("library function `%#D' redeclared as non-function `%#D'", - olddecl, newdecl); - else + /* A near match; override the builtin. */ + + if (TREE_PUBLIC (newdecl)) { - cp_error ("declaration of `%#D'", newdecl); - cp_error ("conflicts with built-in declaration `%#D'", - olddecl); + warning ("new declaration `%#D'", newdecl); + warning ("ambiguates built-in declaration `%#D'", + olddecl); } - return 0; + else if (warn_shadow) + warning ("shadowing %s function `%#D'", + DECL_BUILT_IN (olddecl) ? "built-in" : "library", + olddecl); } + else + /* Discard the old built-in function. */ + return 0; + } - cp_warning ("declaration of `%#D'", newdecl); - cp_warning ("conflicts with built-in declaration `%#D'", - olddecl); + if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl)) + { + /* If a builtin function is redeclared as `static', merge + the declarations, but make the original one static. */ + DECL_THIS_STATIC (olddecl) = 1; + TREE_PUBLIC (olddecl) = 0; + + /* Make the old declaration consistent with the new one so + that all remnants of the builtin-ness of this function + will be banished. */ + SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl)); + SET_DECL_RTL (olddecl, DECL_RTL (newdecl)); + COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl); + SET_IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (newdecl), + newdecl); } } else if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) @@ -3241,7 +3248,7 @@ duplicate_decls (newdecl, olddecl) && DECL_FUNCTION_TEMPLATE_P (newdecl))) return 0; - cp_error ("`%#D' redeclared as different kind of symbol", newdecl); + error ("`%#D' redeclared as different kind of symbol", newdecl); if (TREE_CODE (olddecl) == TREE_LIST) olddecl = TREE_VALUE (olddecl); cp_error_at ("previous declaration of `%#D'", olddecl); @@ -3253,7 +3260,7 @@ duplicate_decls (newdecl, olddecl) } else if (!types_match) { - if (DECL_REAL_CONTEXT (newdecl) != DECL_REAL_CONTEXT (olddecl)) + if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)) /* These are certainly not duplicate declarations; they're from different scopes. */ return 0; @@ -3266,7 +3273,7 @@ duplicate_decls (newdecl, olddecl) if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) { - cp_error ("declaration of template `%#D'", newdecl); + error ("declaration of template `%#D'", newdecl); cp_error_at ("conflicts with previous declaration `%#D'", olddecl); } @@ -3277,24 +3284,23 @@ duplicate_decls (newdecl, olddecl) && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), DECL_TEMPLATE_PARMS (olddecl))) { - cp_error ("new declaration `%#D'", newdecl); + error ("new declaration `%#D'", newdecl); cp_error_at ("ambiguates old declaration `%#D'", olddecl); } return 0; } if (TREE_CODE (newdecl) == FUNCTION_DECL) { - if (DECL_LANGUAGE (newdecl) == lang_c - && DECL_LANGUAGE (olddecl) == lang_c) + if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl)) { - cp_error ("declaration of C function `%#D' conflicts with", + error ("declaration of C function `%#D' conflicts with", newdecl); cp_error_at ("previous declaration `%#D' here", olddecl); } else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)), TYPE_ARG_TYPES (TREE_TYPE (olddecl)))) { - cp_error ("new declaration `%#D'", newdecl); + error ("new declaration `%#D'", newdecl); cp_error_at ("ambiguates old declaration `%#D'", olddecl); } else @@ -3305,18 +3311,18 @@ duplicate_decls (newdecl, olddecl) else if (current_class_type == NULL_TREE || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) { - cp_error ("conflicting types for `%#D'", newdecl); + error ("conflicting types for `%#D'", newdecl); cp_error_at ("previous declaration as `%#D'", olddecl); } } - else if (TREE_CODE (newdecl) == FUNCTION_DECL + else if (TREE_CODE (newdecl) == FUNCTION_DECL && ((DECL_TEMPLATE_SPECIALIZATION (olddecl) && (!DECL_TEMPLATE_INFO (newdecl) - || (DECL_TI_TEMPLATE (newdecl) + || (DECL_TI_TEMPLATE (newdecl) != DECL_TI_TEMPLATE (olddecl)))) || (DECL_TEMPLATE_SPECIALIZATION (newdecl) && (!DECL_TEMPLATE_INFO (olddecl) - || (DECL_TI_TEMPLATE (olddecl) + || (DECL_TI_TEMPLATE (olddecl) != DECL_TI_TEMPLATE (newdecl)))))) /* It's OK to have a template specialization and a non-template with the same type, or to have specializations of two @@ -3327,8 +3333,8 @@ duplicate_decls (newdecl, olddecl) specialize one of its methods. This situation is legal, but the declarations must be merged in the usual way. */ return 0; - else if (TREE_CODE (newdecl) == FUNCTION_DECL - && ((DECL_TEMPLATE_INSTANTIATION (olddecl) + else if (TREE_CODE (newdecl) == FUNCTION_DECL + && ((DECL_TEMPLATE_INSTANTIATION (olddecl) && !DECL_USE_TEMPLATE (newdecl)) || (DECL_TEMPLATE_INSTANTIATION (newdecl) && !DECL_USE_TEMPLATE (olddecl)))) @@ -3345,7 +3351,7 @@ duplicate_decls (newdecl, olddecl) const char *errmsg = redeclaration_error_message (newdecl, olddecl); if (errmsg) { - cp_error (errmsg, newdecl); + error (errmsg, newdecl); if (DECL_NAME (olddecl) != NULL_TREE) cp_error_at ((DECL_INITIAL (olddecl) && namespace_bindings_p ()) @@ -3367,13 +3373,13 @@ duplicate_decls (newdecl, olddecl) /* extern "C" int foo (); int foo () { bar (); } is OK. */ - if (current_lang_stack == current_lang_base) - DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); + if (current_lang_depth () == 0) + SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl)); else { cp_error_at ("previous declaration of `%#D' with %L linkage", olddecl, DECL_LANGUAGE (olddecl)); - cp_error ("conflicts with new declaration with %L linkage", + error ("conflicts with new declaration with %L linkage", DECL_LANGUAGE (newdecl)); } } @@ -3388,7 +3394,7 @@ duplicate_decls (newdecl, olddecl) if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); - + for (; t1 && t1 != void_list_node; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) @@ -3398,7 +3404,7 @@ duplicate_decls (newdecl, olddecl) { if (pedantic) { - cp_pedwarn ("default argument given for parameter %d of `%#D'", + pedwarn ("default argument given for parameter %d of `%#D'", i, newdecl); cp_pedwarn_at ("after previous specification in `%#D'", olddecl); @@ -3406,17 +3412,18 @@ duplicate_decls (newdecl, olddecl) } else { - cp_error ("default argument given for parameter %d of `%#D'", + error ("default argument given for parameter %d of `%#D'", i, newdecl); cp_error_at ("after previous specification in `%#D'", olddecl); } } - if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl) + if (DECL_DECLARED_INLINE_P (newdecl) + && ! DECL_DECLARED_INLINE_P (olddecl) && TREE_ADDRESSABLE (olddecl) && warn_inline) { - cp_warning ("`%#D' was used before it was declared inline", + warning ("`%#D' was used before it was declared inline", newdecl); cp_warning_at ("previous non-inline declaration here", olddecl); @@ -3437,19 +3444,23 @@ duplicate_decls (newdecl, olddecl) definition. */ if (DECL_VINDEX (olddecl)) DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl); + if (DECL_VIRTUAL_CONTEXT (olddecl)) + DECL_VIRTUAL_CONTEXT (newdecl) = DECL_VIRTUAL_CONTEXT (olddecl); if (DECL_CONTEXT (olddecl)) DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); - if (DECL_CLASS_CONTEXT (olddecl)) - DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); - if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) + if (DECL_PENDING_INLINE_INFO (newdecl) == 0) DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl); DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); - DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl); + DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl); DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl); DECL_NEEDS_FINAL_OVERRIDER_P (newdecl) |= DECL_NEEDS_FINAL_OVERRIDER_P (olddecl); + DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl); + if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK) + SET_OVERLOADED_OPERATOR_CODE + (newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl)); new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE; - + /* Optionally warn about more than one declaration for the same name, but don't warn about a function declaration followed by a definition. */ @@ -3458,9 +3469,9 @@ duplicate_decls (newdecl, olddecl) /* Don't warn about extern decl followed by definition. */ && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)) /* Don't warn about friends, let add_friend take care of it. */ - && ! DECL_FRIEND_P (newdecl)) + && ! (DECL_FRIEND_P (newdecl) || DECL_FRIEND_P (olddecl))) { - cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); + warning ("redundant redeclaration of `%D' in same scope", newdecl); cp_warning_at ("previous declaration of `%D'", olddecl); } } @@ -3478,44 +3489,52 @@ duplicate_decls (newdecl, olddecl) CLASSTYPE_FRIEND_CLASSES (newtype) = CLASSTYPE_FRIEND_CLASSES (oldtype); } + + DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl); } /* Copy all the DECL_... slots specified in the new decl except for any that we copy here from the old type. */ - DECL_MACHINE_ATTRIBUTES (newdecl) - = merge_machine_decl_attributes (olddecl, newdecl); + DECL_ATTRIBUTES (newdecl) + = (*targetm.merge_decl_attributes) (olddecl, newdecl); if (TREE_CODE (newdecl) == TEMPLATE_DECL) { - if (! duplicate_decls (DECL_TEMPLATE_RESULT (newdecl), - DECL_TEMPLATE_RESULT (olddecl))) - cp_error ("invalid redeclaration of %D", newdecl); TREE_TYPE (olddecl) = TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)); - DECL_TEMPLATE_SPECIALIZATIONS (olddecl) + DECL_TEMPLATE_SPECIALIZATIONS (olddecl) = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl), DECL_TEMPLATE_SPECIALIZATIONS (newdecl)); - + + /* If the new declaration is a definition, update the file and + line information on the declaration. */ + if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE + && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) != NULL_TREE) + { + DECL_SOURCE_LINE (olddecl) + = DECL_SOURCE_LINE (DECL_TEMPLATE_RESULT (olddecl)) + = DECL_SOURCE_LINE (newdecl); + DECL_SOURCE_FILE (olddecl) + = DECL_SOURCE_FILE (DECL_TEMPLATE_RESULT (olddecl)) + = DECL_SOURCE_FILE (newdecl); + } + return 1; } - + if (types_match) { /* Automatically handles default parameters. */ tree oldtype = TREE_TYPE (olddecl); tree newtype; - /* Make sure we put the new type in the same obstack as the old one. */ - if (oldtype) - push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); - else - { - push_obstacks_nochange (); - end_temporary_allocation (); - } - /* Merge the data types specified in the two decls. */ newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); + /* If common_type produces a non-typedef type, just use the old type. */ + if (TREE_CODE (newdecl) == TYPE_DECL + && newtype == DECL_ORIGINAL_TYPE (newdecl)) + newtype = oldtype; + if (TREE_CODE (newdecl) == VAR_DECL) DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl); /* Do this after calling `common_type' so that default @@ -3529,15 +3548,15 @@ duplicate_decls (newdecl, olddecl) TREE_TYPE (olddecl) = build_exception_variant (newtype, TYPE_RAISES_EXCEPTIONS (oldtype)); - if ((pedantic || (! DECL_IN_SYSTEM_HEADER (olddecl) - && ! DECL_IN_SYSTEM_HEADER (newdecl))) + if ((pedantic || ! DECL_IN_SYSTEM_HEADER (olddecl)) && DECL_SOURCE_LINE (olddecl) != 0 && flag_exceptions - && ! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl))) + && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)), + TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)), 1)) { - cp_pedwarn ("declaration of `%D' throws different exceptions", + error ("declaration of `%F' throws different exceptions", newdecl); - cp_pedwarn_at ("previous declaration here", olddecl); + cp_error_at ("than previous declaration `%F'", olddecl); } } TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; @@ -3569,7 +3588,8 @@ duplicate_decls (newdecl, olddecl) DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); - if (DECL_LANG_SPECIFIC (newdecl) + if (CAN_HAVE_FULL_LANG_DECL_P (newdecl) + && DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl)) DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); } @@ -3581,14 +3601,16 @@ duplicate_decls (newdecl, olddecl) if (DECL_SECTION_NAME (newdecl) == NULL_TREE) DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); - /* Keep the old rtl since we can safely use it, unless it's the - call to abort() used for abstract virtuals. */ - if ((DECL_LANG_SPECIFIC (olddecl) - && !DECL_ABSTRACT_VIRTUAL_P (olddecl)) - || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl)) - DECL_RTL (newdecl) = DECL_RTL (olddecl); + /* Keep the old rtl since we can safely use it. */ + COPY_DECL_RTL (olddecl, newdecl); - pop_obstacks (); + if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl) + |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl); + DECL_NO_LIMIT_STACK (newdecl) + |= DECL_NO_LIMIT_STACK (olddecl); + } } /* If cannot merge, then use the new type and qualifiers, and don't preserve the old rtl. */ @@ -3608,17 +3630,18 @@ duplicate_decls (newdecl, olddecl) /* Merge the storage class information. */ DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl); + DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl); TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl); if (! DECL_EXTERNAL (olddecl)) DECL_EXTERNAL (newdecl) = 0; - + if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl)) { DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl); DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl); DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl); - DECL_TEMPLATE_INSTANTIATED (newdecl) + DECL_TEMPLATE_INSTANTIATED (newdecl) |= DECL_TEMPLATE_INSTANTIATED (olddecl); /* Don't really know how much of the language-specific values we should copy from old to new. */ @@ -3626,6 +3649,8 @@ duplicate_decls (newdecl, olddecl) DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); + DECL_INITIALIZED_IN_CLASS_P (newdecl) + |= DECL_INITIALIZED_IN_CLASS_P (olddecl); olddecl_friend = DECL_FRIEND_P (olddecl); /* Only functions have DECL_BEFRIENDING_CLASSES. */ @@ -3638,8 +3663,8 @@ duplicate_decls (newdecl, olddecl) if (TREE_CODE (newdecl) == FUNCTION_DECL) { - if (DECL_TEMPLATE_INSTANTIATION (olddecl) - && !DECL_TEMPLATE_INSTANTIATION (newdecl)) + if (DECL_TEMPLATE_INSTANTIATION (olddecl) + && !DECL_TEMPLATE_INSTANTIATION (newdecl)) { /* If newdecl is not a specialization, then it is not a template-related function at all. And that means that we @@ -3647,21 +3672,21 @@ duplicate_decls (newdecl, olddecl) my_friendly_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl), 0); - if (TREE_USED (olddecl)) + if (TREE_USED (olddecl)) /* From [temp.expl.spec]: - + If a template, a member template or the member of a class template is explicitly specialized then that specialization shall be declared before the first use of that specialization that would cause an implicit instantiation to take place, in every translation unit in which such a use occurs. */ - cp_error ("explicit specialization of %D after first use", + error ("explicit specialization of %D after first use", olddecl); SET_DECL_TEMPLATE_SPECIALIZATION (olddecl); } - DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl); + DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl); /* If either decl says `inline', this fn is inline, unless its definition was passed already. */ @@ -3669,77 +3694,69 @@ duplicate_decls (newdecl, olddecl) DECL_INLINE (olddecl) = 1; DECL_INLINE (newdecl) = DECL_INLINE (olddecl); + DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl) + = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)); + + /* Preserve abstractness on cloned [cd]tors. */ + DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl); + if (! types_match) { - DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl); - DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl); - DECL_RTL (olddecl) = DECL_RTL (newdecl); + SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl)); + COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl); + SET_DECL_RTL (olddecl, DECL_RTL (newdecl)); } if (! types_match || new_defines_function) { - /* These need to be copied so that the names are available. */ + /* These need to be copied so that the names are available. + Note that if the types do match, we'll preserve inline + info and other bits, but if not, we won't. */ DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl); DECL_RESULT (olddecl) = DECL_RESULT (newdecl); } if (new_defines_function) /* If defining a function declared with other language linkage, use the previously declared language linkage. */ - DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); - else + SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl)); + else if (types_match) { /* If redeclaring a builtin function, and not a definition, it stays built in. */ if (DECL_BUILT_IN (olddecl)) { - DECL_BUILT_IN (newdecl) = 1; + DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); /* If we're keeping the built-in definition, keep the rtl, regardless of declaration matches. */ - DECL_RTL (newdecl) = DECL_RTL (olddecl); + SET_DECL_RTL (newdecl, DECL_RTL (olddecl)); } else - DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); + DECL_NUM_STMTS (newdecl) = DECL_NUM_STMTS (olddecl); DECL_RESULT (newdecl) = DECL_RESULT (olddecl); - if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))) - /* Previously saved insns go together with - the function's previous definition. */ - DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); /* Don't clear out the arguments if we're redefining a function. */ if (DECL_ARGUMENTS (olddecl)) DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); } - if (DECL_LANG_SPECIFIC (olddecl)) - DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl); - } - - if (TREE_CODE (newdecl) == NAMESPACE_DECL) - { - NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl); } + else if (TREE_CODE (newdecl) == NAMESPACE_DECL) + NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl); /* Now preserve various other info from the definition. */ TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); DECL_COMMON (newdecl) = DECL_COMMON (olddecl); - DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl); + COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl); if (TREE_CODE (newdecl) == FUNCTION_DECL) { int function_size; - struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl); - struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl); function_size = sizeof (struct tree_decl); - bcopy ((char *) newdecl + sizeof (struct tree_common), - (char *) olddecl + sizeof (struct tree_common), - function_size - sizeof (struct tree_common)); - - /* Can we safely free the storage used by newdecl? */ - -#define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \ - & ~ obstack_alignment_mask (&permanent_obstack)) + memcpy ((char *) olddecl + sizeof (struct tree_common), + (char *) newdecl + sizeof (struct tree_common), + function_size - sizeof (struct tree_common)); if (DECL_TEMPLATE_INSTANTIATION (newdecl)) { @@ -3747,16 +3764,16 @@ duplicate_decls (newdecl, olddecl) the following sequence of events has occurred: o A friend function was declared in a class template. The - class template was instantiated. + class template was instantiated. - o The instantiation of the friend declaration was - recorded on the instantiation list, and is newdecl. + o The instantiation of the friend declaration was + recorded on the instantiation list, and is newdecl. o Later, however, instantiate_class_template called pushdecl on the newdecl to perform name injection. But, pushdecl in turn called duplicate_decls when it discovered that another declaration of a global function with the same name already - existed. + existed. o Here, in duplicate_decls, we decided to clobber newdecl. @@ -3765,53 +3782,20 @@ duplicate_decls (newdecl, olddecl) instantiations so that if we try to do the instantiation again we won't get the clobbered declaration. */ - tree tmpl = DECL_TI_TEMPLATE (newdecl); - tree decls = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); + tree tmpl = DECL_TI_TEMPLATE (newdecl); + tree decls = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); for (; decls; decls = TREE_CHAIN (decls)) if (TREE_VALUE (decls) == newdecl) TREE_VALUE (decls) = olddecl; } - - if (((char *)newdecl + ROUND (function_size) == (char *)nl - && ((char *)newdecl + ROUND (function_size) - + ROUND (sizeof (struct lang_decl)) - == obstack_next_free (&permanent_obstack))) - || ((char *)newdecl + ROUND (function_size) - == obstack_next_free (&permanent_obstack))) - { - DECL_MAIN_VARIANT (newdecl) = olddecl; - DECL_LANG_SPECIFIC (olddecl) = ol; - bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl)); - - obstack_free (&permanent_obstack, newdecl); - } - else if (LANG_DECL_PERMANENT (ol) && ol != nl) - { - if (DECL_MAIN_VARIANT (olddecl) == olddecl) - { - /* Save these lang_decls that would otherwise be lost. */ - extern tree free_lang_decl_chain; - tree free_lang_decl = (tree) ol; - - if (DECL_LANG_SPECIFIC (olddecl) == ol) - abort (); - - TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; - free_lang_decl_chain = free_lang_decl; - } - else - { - /* Storage leak. */; - } - } } else { - bcopy ((char *) newdecl + sizeof (struct tree_common), - (char *) olddecl + sizeof (struct tree_common), - sizeof (struct tree_decl) - sizeof (struct tree_common) - + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); + memcpy ((char *) olddecl + sizeof (struct tree_common), + (char *) newdecl + sizeof (struct tree_common), + sizeof (struct tree_decl) - sizeof (struct tree_common) + + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); } DECL_UID (olddecl) = olddecl_uid; @@ -3820,7 +3804,7 @@ duplicate_decls (newdecl, olddecl) /* NEWDECL contains the merged attribute lists. Update OLDDECL to be the same. */ - DECL_MACHINE_ATTRIBUTES (olddecl) = DECL_MACHINE_ATTRIBUTES (newdecl); + DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl); return 1; } @@ -3838,8 +3822,15 @@ pushdecl (x) tree x; { register tree t; - register tree name = DECL_ASSEMBLER_NAME (x); - int need_new_binding = 1; + register tree name; + int need_new_binding; + + /* We shouldn't be calling pushdecl when we're generating RTL for a + function that we already did semantic analysis on previously. */ + my_friendly_assert (!cfun || doing_semantic_analysis_p (), + 19990913); + + need_new_binding = 1; if (DECL_TEMPLATE_PARM_P (x)) /* Template parameters have no context; they are not X::T even @@ -3850,68 +3841,124 @@ pushdecl (x) if (current_function_decl && x != current_function_decl /* A local declaration for a function doesn't constitute nesting. */ - && (TREE_CODE (x) != FUNCTION_DECL || DECL_INITIAL (x)) - /* Don't change DECL_CONTEXT of virtual methods. */ - && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x)) + && !(TREE_CODE (x) == FUNCTION_DECL && !DECL_INITIAL (x)) + /* A local declaration for an `extern' variable is in the + scope of the current namespace, not the current + function. */ + && !(TREE_CODE (x) == VAR_DECL && DECL_EXTERNAL (x)) && !DECL_CONTEXT (x)) DECL_CONTEXT (x) = current_function_decl; - if (!DECL_CONTEXT (x)) - DECL_CONTEXT (x) = FROB_CONTEXT (current_namespace); - } - /* Type are looked up using the DECL_NAME, as that is what the rest of the - compiler wants to use. */ - if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL - || TREE_CODE (x) == NAMESPACE_DECL) - name = DECL_NAME (x); + /* If this is the declaration for a namespace-scope function, + but the declaration itself is in a local scope, mark the + declaration. */ + if (TREE_CODE (x) == FUNCTION_DECL + && DECL_NAMESPACE_SCOPE_P (x) + && current_function_decl + && x != current_function_decl) + DECL_LOCAL_FUNCTION_P (x) = 1; + } + name = DECL_NAME (x); if (name) { -#if 0 - /* Not needed...see below. */ - char *file; - int line; -#endif + int different_binding_level = 0; + if (TREE_CODE (name) == TEMPLATE_ID_EXPR) name = TREE_OPERAND (name, 0); - - /* Namespace-scoped variables are not found in the current level. */ - if (TREE_CODE (x) == VAR_DECL && DECL_NAMESPACE_SCOPE_P (x)) + + /* In case this decl was explicitly namespace-qualified, look it + up in its namespace context. */ + if (TREE_CODE (x) == VAR_DECL && DECL_NAMESPACE_SCOPE_P (x) + && namespace_bindings_p ()) t = namespace_binding (name, DECL_CONTEXT (x)); else t = lookup_name_current_level (name); + + /* [basic.link] If there is a visible declaration of an entity + with linkage having the same name and type, ignoring entities + declared outside the innermost enclosing namespace scope, the + block scope declaration declares that same entity and + receives the linkage of the previous declaration. */ + if (! t && current_function_decl && x != current_function_decl + && (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) + && DECL_EXTERNAL (x)) + { + /* Look in block scope. */ + t = IDENTIFIER_VALUE (name); + /* Or in the innermost namespace. */ + if (! t) + t = namespace_binding (name, DECL_CONTEXT (x)); + /* Does it have linkage? Note that if this isn't a DECL, it's an + OVERLOAD, which is OK. */ + if (t && DECL_P (t) && ! (TREE_STATIC (t) || DECL_EXTERNAL (t))) + t = NULL_TREE; + if (t) + different_binding_level = 1; + } + + /* If we are declaring a function, and the result of name-lookup + was an OVERLOAD, look for an overloaded instance that is + actually the same as the function we are declaring. (If + there is one, we have to merge our declaration with the + previous declaration.) */ + if (t && TREE_CODE (t) == OVERLOAD) + { + tree match; + + if (TREE_CODE (x) == FUNCTION_DECL) + for (match = t; match; match = OVL_NEXT (match)) + { + if (decls_match (OVL_CURRENT (match), x)) + break; + } + else + /* Just choose one. */ + match = t; + + if (match) + t = OVL_CURRENT (match); + else + t = NULL_TREE; + } + if (t == error_mark_node) { /* error_mark_node is 0 for a while during initialization! */ t = NULL_TREE; cp_error_at ("`%#D' used prior to declaration", x); } - else if (t != NULL_TREE) { -#if 0 - /* This is turned off until I have time to do it right (bpk). */ - /* With the code below that uses it... */ - file = DECL_SOURCE_FILE (t); - line = DECL_SOURCE_LINE (t); -#endif - if (TREE_CODE (t) == PARM_DECL) + if (different_binding_level) + { + if (decls_match (x, t)) + /* The standard only says that the local extern + inherits linkage from the previous decl; in + particular, default args are not shared. It would + be nice to propagate inlining info, though. FIXME. */ + TREE_PUBLIC (x) = TREE_PUBLIC (t); + } + else if (TREE_CODE (t) == PARM_DECL) { if (DECL_CONTEXT (t) == NULL_TREE) - fatal ("parse errors have confused me too much"); + /* This is probaby caused by too many errors, but calling + abort will say that if errors have occurred. */ + abort (); /* Check for duplicate params. */ if (duplicate_decls (x, t)) return t; } - else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c) + else if ((DECL_EXTERN_C_FUNCTION_P (x) || DECL_FUNCTION_TEMPLATE_P (x)) && is_overloaded_fn (t)) /* Don't do anything just yet. */; else if (t == wchar_decl_node) { if (pedantic && ! DECL_IN_SYSTEM_HEADER (x)) - cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x)); + pedwarn ("redeclaration of `wchar_t' as `%T'", + TREE_TYPE (x)); /* Throw away the redeclaration. */ return t; @@ -3923,36 +3970,6 @@ pushdecl (x) } else if (duplicate_decls (x, t)) { -#if 0 - /* This is turned off until I have time to do it right (bpk). */ - - /* Also warn if they did a prototype with `static' on it, but - then later left the `static' off. */ - if (! TREE_PUBLIC (name) && TREE_PUBLIC (x)) - { - if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t)) - return t; - - if (extra_warnings) - { - cp_warning ("`static' missing from declaration of `%D'", - t); - warning_with_file_and_line (file, line, - "previous declaration of `%s'", - decl_as_string (t, 0)); - } - - /* Now fix things so it'll do what they expect. */ - if (current_function_decl) - TREE_PUBLIC (current_function_decl) = 0; - } - /* Due to interference in memory reclamation (X may be - obstack-deallocated at this point), we must guard against - one really special case. [jason: This should be handled - by start_function] */ - if (current_function_decl == x) - current_function_decl = t; -#endif if (TREE_CODE (t) == TYPE_DECL) SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t)); else if (TREE_CODE (t) == FUNCTION_DECL) @@ -3963,13 +3980,13 @@ pushdecl (x) else if (DECL_MAIN_P (x)) { /* A redeclaration of main, but not a duplicate of the - previous one. + previous one. [basic.start.main] This function shall not be overloaded. */ cp_error_at ("invalid redeclaration of `%D'", t); - cp_error ("as `%D'", x); + error ("as `%D'", x); /* We don't try to push this declaration since that causes a crash. */ return x; @@ -3980,17 +3997,16 @@ pushdecl (x) /* If this is a function conjured up by the backend, massage it so it looks friendly. */ - if (TREE_CODE (x) == FUNCTION_DECL - && ! DECL_LANG_SPECIFIC (x)) + if (DECL_NON_THUNK_FUNCTION_P (x) && ! DECL_LANG_SPECIFIC (x)) { retrofit_lang_decl (x); - DECL_LANGUAGE (x) = lang_c; + SET_DECL_LANGUAGE (x, lang_c); } - if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x)) + if (DECL_NON_THUNK_FUNCTION_P (x) && ! DECL_FUNCTION_MEMBER_P (x)) { t = push_overloaded_decl (x, PUSH_LOCAL); - if (t != x || DECL_LANGUAGE (x) == lang_c) + if (t != x) return t; if (!namespace_bindings_p ()) /* We do not need to create a binding for this name; @@ -3999,7 +4015,12 @@ pushdecl (x) need_new_binding = 0; } else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_NAMESPACE_SCOPE_P (x)) - return push_overloaded_decl (x, PUSH_GLOBAL); + { + t = push_overloaded_decl (x, PUSH_GLOBAL); + if (t == x) + add_decl_to_level (x, NAMESPACE_LEVEL (CP_DECL_CONTEXT (t))); + return t; + } /* If declaring a type as a typedef, copy the type (unless we're at line 0), and install this TYPE_DECL as the new type's typedef @@ -4007,7 +4028,7 @@ pushdecl (x) if (TREE_CODE (x) == TYPE_DECL) { tree type = TREE_TYPE (x); - if (DECL_SOURCE_LINE (x) == 0) + if (DECL_SOURCE_LINE (x) == 0) { if (TYPE_NAME (type) == 0) TYPE_NAME (type) = x; @@ -4016,24 +4037,20 @@ pushdecl (x) /* We don't want to copy the type when all we're doing is making a TYPE_DECL for the purposes of inlining. */ - && (!TYPE_NAME (type) + && (!TYPE_NAME (type) || TYPE_NAME (type) != DECL_ABSTRACT_ORIGIN (x))) { - push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); - DECL_ORIGINAL_TYPE (x) = type; type = build_type_copy (type); TYPE_STUB_DECL (type) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x)); TYPE_NAME (type) = x; TREE_TYPE (x) = type; - - pop_obstacks (); } if (type != error_mark_node && TYPE_NAME (type) && TYPE_IDENTIFIER (type)) - set_identifier_type_value_with_scope (DECL_NAME (x), type, + set_identifier_type_value_with_scope (DECL_NAME (x), type, current_binding_level); } @@ -4042,25 +4059,23 @@ pushdecl (x) We get warnings about inline functions where they are defined. We get warnings about other functions from push_overloaded_decl. - + Avoid duplicate warnings where they are used. */ if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL) { tree decl; - if (IDENTIFIER_NAMESPACE_VALUE (name) != NULL_TREE - && (DECL_EXTERNAL (IDENTIFIER_NAMESPACE_VALUE (name)) - || TREE_PUBLIC (IDENTIFIER_NAMESPACE_VALUE (name)))) - decl = IDENTIFIER_NAMESPACE_VALUE (name); - else - decl = NULL_TREE; + decl = IDENTIFIER_NAMESPACE_VALUE (name); + if (decl && TREE_CODE (decl) == OVERLOAD) + decl = OVL_FUNCTION (decl); - if (decl + if (decl && decl != error_mark_node + && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)) /* If different sort of thing, we already gave an error. */ && TREE_CODE (decl) == TREE_CODE (x) && !same_type_p (TREE_TYPE (x), TREE_TYPE (decl))) { - cp_pedwarn ("type mismatch with previous external decl", x); + pedwarn ("type mismatch with previous external decl", x); cp_pedwarn_at ("previous external decl of `%#D'", decl); } } @@ -4076,15 +4091,15 @@ pushdecl (x) if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x)) TREE_PUBLIC (name) = 1; - if (!(TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) - && t != NULL_TREE)) - { - if (TREE_CODE (x) == FUNCTION_DECL) - my_friendly_assert - ((IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE) - || (IDENTIFIER_GLOBAL_VALUE (name) == x), 378); - SET_IDENTIFIER_NAMESPACE_VALUE (name, x); - } + /* Bind the name for the entity. */ + if (!(TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) + && t != NULL_TREE) + && (TREE_CODE (x) == TYPE_DECL + || TREE_CODE (x) == VAR_DECL + || TREE_CODE (x) == NAMESPACE_DECL + || TREE_CODE (x) == CONST_DECL + || TREE_CODE (x) == TEMPLATE_DECL)) + SET_IDENTIFIER_NAMESPACE_VALUE (name, x); /* Don't forget if the function was used via an implicit decl. */ if (IDENTIFIER_IMPLICIT_DECL (name) @@ -4101,7 +4116,7 @@ pushdecl (x) /* If this real decl matches the implicit, don't complain. */ && ! (TREE_CODE (x) == FUNCTION_DECL && TREE_TYPE (TREE_TYPE (x)) == integer_type_node)) - cp_warning + warning ("`%D' was previously implicitly declared to return `int'", x); /* If new decl is `static' and an `extern' was seen previously, @@ -4126,16 +4141,29 @@ pushdecl (x) /* If this is a TYPE_DECL, push it into the type value slot. */ if (TREE_CODE (x) == TYPE_DECL) - set_identifier_type_value_with_scope (name, TREE_TYPE (x), + set_identifier_type_value_with_scope (name, TREE_TYPE (x), current_binding_level); /* Clear out any TYPE_DECL shadowed by a namespace so that we won't think this is a type. The C struct hack doesn't go through namespaces. */ if (TREE_CODE (x) == NAMESPACE_DECL) - set_identifier_type_value_with_scope (name, NULL_TREE, + set_identifier_type_value_with_scope (name, NULL_TREE, current_binding_level); + if (oldlocal) + { + tree d = oldlocal; + + while (oldlocal + && TREE_CODE (oldlocal) == VAR_DECL + && DECL_DEAD_FOR_LOCAL (oldlocal)) + oldlocal = DECL_SHADOWED_FOR_VAR (oldlocal); + + if (oldlocal == NULL_TREE) + oldlocal = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (d)); + } + /* If this is an extern function declaration, see if we have a global definition or declaration for the function. */ if (oldlocal == NULL_TREE @@ -4149,7 +4177,7 @@ pushdecl (x) /* OK */; else { - cp_warning ("extern declaration of `%#D' doesn't match", x); + warning ("extern declaration of `%#D' doesn't match", x); cp_warning_at ("global declaration `%#D'", oldglobal); } } @@ -4162,58 +4190,54 @@ pushdecl (x) && TREE_PUBLIC (x)) TREE_PUBLIC (name) = 1; - if (DECL_FROM_INLINE (x)) - /* Inline decls shadow nothing. */; - /* Warn if shadowing an argument at the top level of the body. */ - else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) - && TREE_CODE (oldlocal) == PARM_DECL - /* Don't complain if it's from an enclosing function. */ - && DECL_CONTEXT (oldlocal) == current_function_decl - && TREE_CODE (x) != PARM_DECL) + if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) + /* Inline decls shadow nothing. */ + && !DECL_FROM_INLINE (x) + && TREE_CODE (oldlocal) == PARM_DECL) { - /* Go to where the parms should be and see if we - find them there. */ - struct binding_level *b = current_binding_level->level_chain; + bool err = false; - if (cleanup_label) - b = b->level_chain; + /* Don't complain if it's from an enclosing function. */ + if (DECL_CONTEXT (oldlocal) == current_function_decl + && TREE_CODE (x) != PARM_DECL) + { + /* Go to where the parms should be and see if we find + them there. */ + struct binding_level *b = current_binding_level->level_chain; + + /* ARM $8.3 */ + if (b->parm_flag == 1) + { + error ("declaration of `%#D' shadows a parameter", + name); + err = true; + } + } - /* ARM $8.3 */ - if (b->parm_flag == 1) - cp_error ("declaration of `%#D' shadows a parameter", name); + if (warn_shadow && !err) + shadow_warning ("a parameter", name, oldlocal); } - else if (warn_shadow && oldlocal != NULL_TREE - && current_binding_level->is_for_scope - && !DECL_DEAD_FOR_LOCAL (oldlocal)) - { - warning ("variable `%s' shadows local", - IDENTIFIER_POINTER (name)); - cp_warning_at (" this is the shadowed declaration", oldlocal); - } + /* Maybe warn if shadowing something else. */ else if (warn_shadow && !DECL_EXTERNAL (x) - /* No shadow warnings for internally generated vars. */ - && ! DECL_ARTIFICIAL (x) - /* No shadow warnings for vars made for inlining. */ - && ! DECL_FROM_INLINE (x)) + /* No shadow warnings for internally generated vars. */ + && ! DECL_ARTIFICIAL (x) + /* No shadow warnings for vars made for inlining. */ + && ! DECL_FROM_INLINE (x)) { - const char *warnstring = NULL; - - if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) - warnstring = "declaration of `%s' shadows a parameter"; - else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE + if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE && current_class_ptr && !TREE_STATIC (name)) - warnstring = "declaration of `%s' shadows a member of `this'"; - else if (oldlocal != NULL_TREE) - warnstring = "declaration of `%s' shadows previous local"; - else if (oldglobal != NULL_TREE) + warning ("declaration of `%s' shadows a member of `this'", + IDENTIFIER_POINTER (name)); + else if (oldlocal != NULL_TREE + && TREE_CODE (oldlocal) == VAR_DECL) + shadow_warning ("a previous local", name, oldlocal); + else if (oldglobal != NULL_TREE + && TREE_CODE (oldglobal) == VAR_DECL) /* XXX shadow warnings in outer-more namespaces */ - warnstring = "declaration of `%s' shadows global declaration"; - - if (warnstring) - warning (warnstring, IDENTIFIER_POINTER (name)); + shadow_warning ("a global declaration", name, oldglobal); } } @@ -4223,25 +4247,26 @@ pushdecl (x) /* Keep count of variables in this level with incomplete type. */ if (TREE_CODE (x) == VAR_DECL && TREE_TYPE (x) != error_mark_node - && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE + && ((!COMPLETE_TYPE_P (TREE_TYPE (x)) && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) /* RTTI TD entries are created while defining the type_info. */ || (TYPE_LANG_SPECIFIC (TREE_TYPE (x)) && TYPE_BEING_DEFINED (TREE_TYPE (x))))) - current_binding_level->incomplete - = tree_cons (NULL_TREE, x, current_binding_level->incomplete); + { + if (namespace_bindings_p ()) + namespace_scope_incomplete + = tree_cons (NULL_TREE, x, namespace_scope_incomplete); + else + current_binding_level->incomplete + = tree_cons (NULL_TREE, x, current_binding_level->incomplete); + } } if (need_new_binding) - { - /* Put decls on list in reverse order. - We will reverse them later if necessary. */ - TREE_CHAIN (x) = current_binding_level->names; - current_binding_level->names = x; - if (current_binding_level == global_binding_level - && !TREE_PERMANENT (x)) - my_friendly_abort (124); - } + add_decl_to_level (x, + DECL_NAMESPACE_SCOPE_P (x) + ? NAMESPACE_LEVEL (CP_DECL_CONTEXT (x)) + : current_binding_level); return x; } @@ -4329,10 +4354,9 @@ tree pushdecl_top_level (x) tree x; { - tree cur_namespace = current_namespace; - current_namespace = global_namespace; + push_to_top_level (); x = pushdecl_namespace_level (x); - current_namespace = cur_namespace; + pop_from_top_level (); return x; } @@ -4356,7 +4380,7 @@ pushdecl_class_level (x) if (TREE_CODE (x) == TYPE_DECL) set_identifier_type_value (name, TREE_TYPE (x)); } - else if (ANON_UNION_TYPE_P (TREE_TYPE (x))) + else if (ANON_AGGR_TYPE_P (TREE_TYPE (x))) { tree f; @@ -4367,28 +4391,35 @@ pushdecl_class_level (x) } } -#if 0 -/* This function is used to push the mangled decls for nested types into - the appropriate scope. Previously pushdecl_top_level was used, but that - is incorrect for members of local classes. */ +/* Enter DECL into the symbol table, if that's appropriate. Returns + DECL, or a modified version thereof. */ -void -pushdecl_nonclass_level (x) - tree x; +tree +maybe_push_decl (decl) + tree decl; { - struct binding_level *b = current_binding_level; - - my_friendly_assert (b->parm_flag != 2, 180); - -#if 0 - /* Get out of template binding levels */ - while (b->pseudo_global) - b = b->level_chain; -#endif + tree type = TREE_TYPE (decl); - pushdecl_with_scope (x, b); + /* Add this decl to the current binding level, but not if it comes + from another scope, e.g. a static member variable. TEM may equal + DECL or it may be a previous decl of the same name. */ + if (decl == error_mark_node + || (TREE_CODE (decl) != PARM_DECL + && DECL_CONTEXT (decl) != NULL_TREE + /* Definitions of namespace members outside their namespace are + possible. */ + && TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL) + || (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ()) + || TREE_CODE (type) == UNKNOWN_TYPE + /* The declaration of a template specialization does not affect + the functions available for overload resolution, so we do not + call pushdecl. */ + || (TREE_CODE (decl) == FUNCTION_DECL + && DECL_TEMPLATE_SPECIALIZATION (decl))) + return decl; + else + return pushdecl (decl); } -#endif /* Make the declaration(s) of X appear in CLASS scope under the name NAME. */ @@ -4399,7 +4430,7 @@ push_class_level_binding (name, x) tree x; { tree binding; - /* The class_binding_level will be NULL if x is a template + /* The class_binding_level will be NULL if x is a template parameter name in a member template. */ if (!class_binding_level) return; @@ -4413,7 +4444,7 @@ push_class_level_binding (name, x) class, then we will need to restore IDENTIFIER_CLASS_VALUE when we leave this class. Record the shadowed declaration here. */ binding = IDENTIFIER_BINDING (name); - if (binding + if (binding && ((TREE_CODE (x) == OVERLOAD && BINDING_VALUE (binding) && is_overloaded_fn (BINDING_VALUE (binding))) @@ -4440,9 +4471,8 @@ push_class_level_binding (name, x) else old_decl = BINDING_VALUE (binding); - /* There was already a binding for X containing fewer - functions than are named in X. Find the previous - declaration of X on the class-shadowed list, and update it. */ + /* Find the previous binding of name on the class-shadowed + list, and update it. */ for (shadow = class_binding_level->class_shadowed; shadow; shadow = TREE_CHAIN (shadow)) @@ -4452,29 +4482,28 @@ push_class_level_binding (name, x) BINDING_VALUE (binding) = x; INHERITED_VALUE_BINDING_P (binding) = 0; TREE_TYPE (shadow) = x; + IDENTIFIER_CLASS_VALUE (name) = x; return; } } /* If we didn't replace an existing binding, put the binding on the - stack of bindings for the identifier, and update - IDENTIFIER_CLASS_VALUE. */ + stack of bindings for the identifier, and update the shadowed list. */ if (push_class_binding (name, x)) { - push_cache_obstack (); class_binding_level->class_shadowed - = tree_cons (name, IDENTIFIER_CLASS_VALUE (name), + = tree_cons (name, NULL, class_binding_level->class_shadowed); - pop_obstacks (); /* Record the value we are binding NAME to so that we can know what to pop later. */ TREE_TYPE (class_binding_level->class_shadowed) = x; } } -/* Insert another USING_DECL into the current binding level, - returning this declaration. If this is a redeclaration, - do nothing and return NULL_TREE. */ +/* Insert another USING_DECL into the current binding level, returning + this declaration. If this is a redeclaration, do nothing, and + return NULL_TREE if this not in namespace scope (in namespace + scope, a using decl might extend any previous bindings). */ tree push_using_decl (scope, name) @@ -4482,14 +4511,14 @@ push_using_decl (scope, name) tree name; { tree decl; - + my_friendly_assert (TREE_CODE (scope) == NAMESPACE_DECL, 383); my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 384); for (decl = current_binding_level->usings; decl; decl = TREE_CHAIN (decl)) if (DECL_INITIAL (decl) == scope && DECL_NAME (decl) == name) break; if (decl) - return NULL_TREE; + return namespace_bindings_p () ? decl : NULL_TREE; decl = build_lang_decl (USING_DECL, name, void_type_node); DECL_INITIAL (decl) = scope; TREE_CHAIN (decl) = current_binding_level->usings; @@ -4507,7 +4536,7 @@ push_using_directive (used) { tree ud = current_binding_level->using_directives; tree iter, ancestor; - + /* Check if we already have this. */ if (purpose_member (used, ud) != NULL_TREE) return NULL_TREE; @@ -4518,7 +4547,7 @@ push_using_directive (used) ancestor = namespace_ancestor (current_decl_namespace (), used); ud = current_binding_level->using_directives; - ud = perm_tree_cons (used, ancestor, ud); + ud = tree_cons (used, ancestor, ud); current_binding_level->using_directives = ud; return ud; } @@ -4529,14 +4558,14 @@ push_using_directive (used) want to be referenced by that name. It is then up to the users of that name to decide what to do with that list. - DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT - slot. It is dealt with the same way. + DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its + DECL_TEMPLATE_RESULT. It is dealt with the same way. FLAGS is a bitwise-or of the following values: PUSH_LOCAL: Bind DECL in the current scope, rather than at namespace scope. PUSH_USING: DECL is being pushed as the result of a using - declaration. + declaration. The value returned may be a previous declaration if we guessed wrong about what language DECL should belong to (C or C++). Otherwise, @@ -4553,17 +4582,7 @@ push_overloaded_decl (decl, flags) int doing_global = (namespace_bindings_p () || !(flags & PUSH_LOCAL)); if (doing_global) - { - old = namespace_binding (name, DECL_CONTEXT (decl)); - if (old && TREE_CODE (old) == FUNCTION_DECL - && DECL_ARTIFICIAL (old) - && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old))) - { - if (duplicate_decls (decl, old)) - return old; - old = NULL_TREE; - } - } + old = namespace_binding (name, DECL_CONTEXT (decl)); else old = lookup_name_current_level (name); @@ -4575,13 +4594,13 @@ push_overloaded_decl (decl, flags) if (IS_AGGR_TYPE (t) && warn_shadow && (! DECL_IN_SYSTEM_HEADER (decl) || ! DECL_IN_SYSTEM_HEADER (old))) - cp_warning ("`%#D' hides constructor for `%#T'", decl, t); + warning ("`%#D' hides constructor for `%#T'", decl, t); old = NULL_TREE; } else if (is_overloaded_fn (old)) { tree tmp; - + for (tmp = old; tmp; tmp = OVL_NEXT (tmp)) { tree fn = OVL_CURRENT (tmp); @@ -4590,17 +4609,20 @@ push_overloaded_decl (decl, flags) && !(flags & PUSH_USING) && compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)), TYPE_ARG_TYPES (TREE_TYPE (decl)))) - cp_error ("`%#D' conflicts with previous using declaration `%#D'", + error ("`%#D' conflicts with previous using declaration `%#D'", decl, fn); - + if (duplicate_decls (decl, fn)) return fn; } } + else if (old == error_mark_node) + /* Ignore the undefined symbol marker. */ + old = NULL_TREE; else { cp_error_at ("previous non-function declaration `%#D'", old); - cp_error ("conflicts with function declaration `%#D'", decl); + error ("conflicts with function declaration `%#D'", decl); return decl; } } @@ -4631,7 +4653,7 @@ push_overloaded_decl (decl, flags) if (TREE_CODE (new_binding) == OVERLOAD && old) { tree *d; - + for (d = &BINDING_LEVEL (IDENTIFIER_BINDING (name))->names; *d; d = &TREE_CHAIN (*d)) @@ -4644,7 +4666,8 @@ push_overloaded_decl (decl, flags) TREE_VALUE (*d) = new_binding; else /* Build a TREE_LIST to wrap the OVERLOAD. */ - *d = build_tree_list (NULL_TREE, new_binding); + *d = tree_cons (NULL_TREE, new_binding, + TREE_CHAIN (*d)); /* And update the CPLUS_BINDING node. */ BINDING_VALUE (IDENTIFIER_BINDING (name)) @@ -4653,7 +4676,7 @@ push_overloaded_decl (decl, flags) } /* We should always find a previous binding in this case. */ - my_friendly_abort (0); + abort (); } /* Install the new binding. */ @@ -4671,15 +4694,6 @@ implicitly_declare (functionid) tree functionid; { register tree decl; - int temp = allocation_temporary_p (); - - push_obstacks_nochange (); - - /* Save the decl permanently so we can warn if definition follows. - In ANSI C, warn_implicit is usually false, so the saves little space. - But in C++, it's usually true, hence the extra code. */ - if (temp && (! warn_implicit || toplevel_bindings_p ())) - end_temporary_allocation (); /* We used to reuse an old implicit decl here, but this loses with inline functions because it can clobber @@ -4689,22 +4703,20 @@ implicitly_declare (functionid) DECL_EXTERNAL (decl) = 1; TREE_PUBLIC (decl) = 1; - /* ANSI standard says implicit declarations are in the innermost block. + /* ISO standard says implicit declarations are in the innermost block. So we record the decl in the standard fashion. */ pushdecl (decl); - rest_of_decl_compilation (decl, NULL_PTR, 0, 0); + rest_of_decl_compilation (decl, NULL, 0, 0); if (warn_implicit /* Only one warning per identifier. */ && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE) { - cp_pedwarn ("implicit declaration of function `%#D'", decl); + pedwarn ("implicit declaration of function `%#D'", decl); } SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl); - pop_obstacks (); - return decl; } @@ -4733,7 +4745,7 @@ redeclaration_error_message (newdecl, olddecl) /* If this is a pure function, its olddecl will actually be the original initialization to `0' (which we force to call abort()). Don't complain about redefinition in this case. */ - if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) + if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)) return 0; /* If both functions come from different namespaces, this is not @@ -4759,15 +4771,17 @@ redeclaration_error_message (newdecl, olddecl) else if (TREE_CODE (newdecl) == TEMPLATE_DECL) { if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL + && (DECL_TEMPLATE_RESULT (newdecl) + != DECL_TEMPLATE_RESULT (olddecl)) && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl))) || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL - && TYPE_SIZE (TREE_TYPE (newdecl)) - && TYPE_SIZE (TREE_TYPE (olddecl)))) + && COMPLETE_TYPE_P (TREE_TYPE (newdecl)) + && COMPLETE_TYPE_P (TREE_TYPE (olddecl)))) return "redefinition of `%#D'"; return 0; } - else if (toplevel_bindings_p ()) + else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl)) { /* Objects declared at top level: */ /* If at least one is a reference, it's ok. */ @@ -4787,32 +4801,51 @@ redeclaration_error_message (newdecl, olddecl) } } -/* Get the LABEL_DECL corresponding to identifier ID as a label. - Create one if none exists so far for the current function. - This function is called for both label definitions and label references. */ +/* Create a new label, named ID. */ -tree -lookup_label (id) +static tree +make_label_decl (id, local_p) tree id; + int local_p; { - register tree decl = IDENTIFIER_LABEL_VALUE (id); + tree decl; - if (current_function_decl == NULL_TREE) - { - error ("label `%s' referenced outside of any function", - IDENTIFIER_POINTER (id)); - return NULL_TREE; - } + decl = build_decl (LABEL_DECL, id, void_type_node); + if (expanding_p) + /* Make sure every label has an rtx. */ + label_rtx (decl); + + DECL_CONTEXT (decl) = current_function_decl; + DECL_MODE (decl) = VOIDmode; + C_DECLARED_LABEL_FLAG (decl) = local_p; - if ((decl == NULL_TREE - || DECL_SOURCE_LINE (decl) == 0) - && (named_label_uses == NULL - || named_label_uses->names_in_scope != current_binding_level->names - || named_label_uses->label_decl != decl)) + /* Say where one reference is to the label, for the sake of the + error if it is not defined. */ + DECL_SOURCE_LINE (decl) = lineno; + DECL_SOURCE_FILE (decl) = input_filename; + + /* Record the fact that this identifier is bound to this label. */ + SET_IDENTIFIER_LABEL_VALUE (id, decl); + + return decl; +} + +/* Record this label on the list of used labels so that we can check + at the end of the function to see whether or not the label was + actually defined, and so we can check when the label is defined whether + this use is valid. */ + +static void +use_label (decl) + tree decl; +{ + if (named_label_uses == NULL + || named_label_uses->names_in_scope != current_binding_level->names + || named_label_uses->label_decl != decl) { - struct named_label_list *new_ent; - new_ent - = (struct named_label_list*)oballoc (sizeof (struct named_label_list)); + struct named_label_use_list *new_ent; + new_ent = ((struct named_label_use_list *) + ggc_alloc (sizeof (struct named_label_use_list))); new_ent->label_decl = decl; new_ent->names_in_scope = current_binding_level->names; new_ent->binding_level = current_binding_level; @@ -4821,61 +4854,265 @@ lookup_label (id) new_ent->next = named_label_uses; named_label_uses = new_ent; } +} + +/* Look for a label named ID in the current function. If one cannot + be found, create one. (We keep track of used, but undefined, + labels, and complain about them at the end of a function.) */ + +tree +lookup_label (id) + tree id; +{ + tree decl; + struct named_label_list *ent; - /* Use a label already defined or ref'd with this name. */ - if (decl != NULL_TREE) + /* You can't use labels at global scope. */ + if (current_function_decl == NULL_TREE) { - /* But not if it is inherited and wasn't declared to be inheritable. */ - if (DECL_CONTEXT (decl) != current_function_decl - && ! C_DECLARED_LABEL_FLAG (decl)) - return shadow_label (id); - return decl; + error ("label `%s' referenced outside of any function", + IDENTIFIER_POINTER (id)); + return NULL_TREE; } - decl = build_decl (LABEL_DECL, id, void_type_node); + /* See if we've already got this label. */ + decl = IDENTIFIER_LABEL_VALUE (id); + if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl) + return decl; - /* Make sure every label has an rtx. */ - label_rtx (decl); + /* Record this label on the list of labels used in this function. + We do this before calling make_label_decl so that we get the + IDENTIFIER_LABEL_VALUE before the new label is declared. */ + ent = ((struct named_label_list *) + ggc_alloc_cleared (sizeof (struct named_label_list))); + ent->old_value = IDENTIFIER_LABEL_VALUE (id); + ent->next = named_labels; + named_labels = ent; - /* A label not explicitly declared must be local to where it's ref'd. */ - DECL_CONTEXT (decl) = current_function_decl; + /* We need a new label. */ + decl = make_label_decl (id, /*local_p=*/0); - DECL_MODE (decl) = VOIDmode; + /* Now fill in the information we didn't have before. */ + ent->label_decl = decl; - /* Say where one reference is to the label, - for the sake of the error if it is not defined. */ - DECL_SOURCE_LINE (decl) = lineno; - DECL_SOURCE_FILE (decl) = input_filename; + return decl; +} - SET_IDENTIFIER_LABEL_VALUE (id, decl); +/* Declare a local label named ID. */ + +tree +declare_local_label (id) + tree id; +{ + tree decl; - named_labels = tree_cons (NULL_TREE, decl, named_labels); - named_label_uses->label_decl = decl; + /* Add a new entry to the SHADOWED_LABELS list so that when we leave + this scope we can restore the old value of + IDENTIFIER_TYPE_VALUE. */ + current_binding_level->shadowed_labels + = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE, + current_binding_level->shadowed_labels); + /* Look for the label. */ + decl = make_label_decl (id, /*local_p=*/1); + /* Now fill in the information we didn't have before. */ + TREE_VALUE (current_binding_level->shadowed_labels) = decl; return decl; } -/* Make a label named NAME in the current function, - shadowing silently any that may be inherited from containing functions - or containing scopes. +/* Returns nonzero if it is ill-formed to jump past the declaration of + DECL. Returns 2 if it's also a real problem. */ + +static int +decl_jump_unsafe (decl) + tree decl; +{ + if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl)) + return 0; - Note that valid use, if the label being shadowed - comes from another scope in the same function, - requires calling declare_nonlocal_label right away. */ + if (DECL_INITIAL (decl) == NULL_TREE + && pod_type_p (TREE_TYPE (decl))) + return 0; -tree -shadow_label (name) - tree name; + /* This is really only important if we're crossing an initialization. + The POD stuff is just pedantry; why should it matter if the class + contains a field of pointer to member type? */ + if (DECL_INITIAL (decl) + || (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))) + return 2; + return 1; +} + +/* Check that a single previously seen jump to a newly defined label + is OK. DECL is the LABEL_DECL or 0; LEVEL is the binding_level for + the jump context; NAMES are the names in scope in LEVEL at the jump + context; FILE and LINE are the source position of the jump or 0. */ + +static void +check_previous_goto_1 (decl, level, names, file, line) + tree decl; + struct binding_level *level; + tree names; + const char *file; + int line; { - register tree decl = IDENTIFIER_LABEL_VALUE (name); + int identified = 0; + int saw_eh = 0; + struct binding_level *b = current_binding_level; + for (; b; b = b->level_chain) + { + tree new_decls = b->names; + tree old_decls = (b == level ? names : NULL_TREE); + for (; new_decls != old_decls; + new_decls = TREE_CHAIN (new_decls)) + { + int problem = decl_jump_unsafe (new_decls); + if (! problem) + continue; - if (decl != NULL_TREE) + if (! identified) + { + if (decl) + pedwarn ("jump to label `%D'", decl); + else + pedwarn ("jump to case label"); + + if (file) + pedwarn_with_file_and_line (file, line, " from here"); + identified = 1; + } + + if (problem > 1) + cp_error_at (" crosses initialization of `%#D'", + new_decls); + else + cp_pedwarn_at (" enters scope of non-POD `%#D'", + new_decls); + } + + if (b == level) + break; + if ((b->is_try_scope || b->is_catch_scope) && ! saw_eh) + { + if (! identified) + { + if (decl) + pedwarn ("jump to label `%D'", decl); + else + pedwarn ("jump to case label"); + + if (file) + pedwarn_with_file_and_line (file, line, " from here"); + identified = 1; + } + if (b->is_try_scope) + error (" enters try block"); + else + error (" enters catch block"); + saw_eh = 1; + } + } +} + +static void +check_previous_goto (use) + struct named_label_use_list *use; +{ + check_previous_goto_1 (use->label_decl, use->binding_level, + use->names_in_scope, use->filename_o_goto, + use->lineno_o_goto); +} + +static void +check_switch_goto (level) + struct binding_level *level; +{ + check_previous_goto_1 (NULL_TREE, level, level->names, NULL, 0); +} + +/* Check that any previously seen jumps to a newly defined label DECL + are OK. Called by define_label. */ + +static void +check_previous_gotos (decl) + tree decl; +{ + struct named_label_use_list **usep; + + if (! TREE_USED (decl)) + return; + + for (usep = &named_label_uses; *usep; ) { - shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); - SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); + struct named_label_use_list *use = *usep; + if (use->label_decl == decl) + { + check_previous_goto (use); + *usep = use->next; + } + else + usep = &(use->next); } +} + +/* Check that a new jump to a label DECL is OK. Called by + finish_goto_stmt. */ - return lookup_label (name); +void +check_goto (decl) + tree decl; +{ + int identified = 0; + tree bad; + struct named_label_list *lab; + + /* We can't know where a computed goto is jumping. So we assume + that it's OK. */ + if (! DECL_P (decl)) + return; + + /* If the label hasn't been defined yet, defer checking. */ + if (! DECL_INITIAL (decl)) + { + use_label (decl); + return; + } + + for (lab = named_labels; lab; lab = lab->next) + if (decl == lab->label_decl) + break; + + /* If the label is not on named_labels it's a gcc local label, so + it must be in an outer scope, so jumping to it is always OK. */ + if (lab == 0) + return; + + if ((lab->in_try_scope || lab->in_catch_scope || lab->bad_decls) + && !identified) + { + cp_pedwarn_at ("jump to label `%D'", decl); + pedwarn (" from here"); + identified = 1; + } + + for (bad = lab->bad_decls; bad; bad = TREE_CHAIN (bad)) + { + tree b = TREE_VALUE (bad); + int u = decl_jump_unsafe (b); + + if (u > 1 && DECL_ARTIFICIAL (b)) + /* Can't skip init of __exception_info. */ + cp_error_at (" enters catch block", b); + else if (u > 1) + cp_error_at (" skips initialization of `%#D'", b); + else + cp_pedwarn_at (" enters scope of non-POD `%#D'", b); + } + + if (lab->in_try_scope) + error (" enters try block"); + else if (lab->in_catch_scope) + error (" enters catch block"); } /* Define a label, specifying the location in the source file. @@ -4884,132 +5121,44 @@ shadow_label (name) tree define_label (filename, line, name) - char *filename; + const char *filename; int line; tree name; { - tree decl; - - if (minimal_parse_mode) - { - push_obstacks (&permanent_obstack, &permanent_obstack); - decl = build_decl (LABEL_DECL, name, void_type_node); - pop_obstacks (); - DECL_SOURCE_LINE (decl) = line; - DECL_SOURCE_FILE (decl) = filename; - add_tree (decl); - return decl; - } + tree decl = lookup_label (name); + struct named_label_list *ent; + register struct binding_level *p; - decl = lookup_label (name); + for (ent = named_labels; ent; ent = ent->next) + if (ent->label_decl == decl) + break; - /* After labels, make any new cleanups go into their + /* After labels, make any new cleanups in the function go into their own new (temporary) binding contour. */ - current_binding_level->more_cleanups_ok = 0; - - /* If label with this name is known from an outer context, shadow it. */ - if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl) - { - shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); - SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); - decl = lookup_label (name); - } + for (p = current_binding_level; !(p->parm_flag); p = p->level_chain) + p->more_cleanups_ok = 0; if (name == get_identifier ("wchar_t")) - cp_pedwarn ("label named wchar_t"); + pedwarn ("label named wchar_t"); if (DECL_INITIAL (decl) != NULL_TREE) { - cp_error ("duplicate label `%D'", decl); + error ("duplicate label `%D'", decl); return 0; } else { - struct named_label_list *uses, *prev; - int identified = 0; - /* Mark label as having been defined. */ DECL_INITIAL (decl) = error_mark_node; /* Say where in the source. */ DECL_SOURCE_FILE (decl) = filename; DECL_SOURCE_LINE (decl) = line; - - prev = NULL; - uses = named_label_uses; - while (uses != NULL) - if (uses->label_decl == decl) - { - struct binding_level *b = current_binding_level; - while (b) - { - tree new_decls = b->names; - tree old_decls = (b == uses->binding_level) - ? uses->names_in_scope : NULL_TREE; - while (new_decls != old_decls) - { - if (TREE_CODE (new_decls) == VAR_DECL - /* Don't complain about crossing initialization - of internal entities. They can't be accessed, - and they should be cleaned up - by the time we get to the label. */ - && ! DECL_ARTIFICIAL (new_decls) - && !(DECL_INITIAL (new_decls) == NULL_TREE - && pod_type_p (TREE_TYPE (new_decls)))) - { - /* This is really only important if we're crossing - an initialization. The POD stuff is just - pedantry; why should it matter if the class - contains a field of pointer to member type? */ - int problem = (DECL_INITIAL (new_decls) - || (TYPE_NEEDS_CONSTRUCTING - (TREE_TYPE (new_decls)))); - - if (! identified) - { - if (problem) - { - cp_error ("jump to label `%D'", decl); - error_with_file_and_line - (uses->filename_o_goto, - uses->lineno_o_goto, " from here"); - } - else - { - cp_pedwarn ("jump to label `%D'", decl); - pedwarn_with_file_and_line - (uses->filename_o_goto, - uses->lineno_o_goto, " from here"); - } - identified = 1; - } - - if (problem) - cp_error_at (" crosses initialization of `%#D'", - new_decls); - else - cp_pedwarn_at (" enters scope of non-POD `%#D'", - new_decls); - } - new_decls = TREE_CHAIN (new_decls); - } - if (b == uses->binding_level) - break; - b = b->level_chain; - } - - if (prev != NULL) - prev->next = uses->next; - else - named_label_uses = uses->next; - - uses = uses->next; - } - else - { - prev = uses; - uses = uses->next; - } - current_function_return_value = NULL_TREE; + if (ent) + { + ent->names_in_scope = current_binding_level->names; + ent->binding_level = current_binding_level; + } + check_previous_gotos (decl); return decl; } } @@ -5018,78 +5167,101 @@ struct cp_switch { struct binding_level *level; struct cp_switch *next; + /* The SWITCH_STMT being built. */ + tree switch_stmt; + /* A splay-tree mapping the low element of a case range to the high + element, or NULL_TREE if there is no high element. Used to + determine whether or not a new case label duplicates an old case + label. We need a tree, rather than simply a hash table, because + of the GNU case range extension. */ + splay_tree cases; }; +/* A stack of the currently active switch statements. The innermost + switch statement is on the top of the stack. There is no need to + mark the stack for garbage collection because it is only active + during the processing of the body of a function, and we never + collect at that point. */ + static struct cp_switch *switch_stack; +/* Called right after a switch-statement condition is parsed. + SWITCH_STMT is the switch statement being parsed. */ + void -push_switch () +push_switch (switch_stmt) + tree switch_stmt; { struct cp_switch *p - = (struct cp_switch *) oballoc (sizeof (struct cp_switch)); + = (struct cp_switch *) xmalloc (sizeof (struct cp_switch)); p->level = current_binding_level; p->next = switch_stack; + p->switch_stmt = switch_stmt; + p->cases = splay_tree_new (case_compare, NULL, NULL); switch_stack = p; } void pop_switch () { + struct cp_switch *cs; + + cs = switch_stack; + splay_tree_delete (cs->cases); switch_stack = switch_stack->next; + free (cs); } -/* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ -/* XXX Note decl is never actually used. (bpk) */ +/* Note that we've seen a definition of a case label, and complain if this + is a bad place for one. */ -void -define_case_label () +tree +finish_case_label (low_value, high_value) + tree low_value; + tree high_value; { - tree cleanup = last_cleanup_this_contour (); - struct binding_level *b = current_binding_level; - int identified = 0; + tree cond, r; + register struct binding_level *p; - if (cleanup) + if (! switch_stack) { - static int explained = 0; - cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup)); - warning ("where case label appears here"); - if (!explained) - { - warning ("(enclose actions of previous case statements requiring"); - warning ("destructors in their own binding contours.)"); - explained = 1; - } + if (high_value) + error ("case label not within a switch statement"); + else if (low_value) + error ("case label `%E' not within a switch statement", + low_value); + else + error ("`default' label not within a switch statement"); + return NULL_TREE; } - for (; b && b != switch_stack->level; b = b->level_chain) + if (processing_template_decl) { - tree new_decls = b->names; - for (; new_decls; new_decls = TREE_CHAIN (new_decls)) - { - if (TREE_CODE (new_decls) == VAR_DECL - /* Don't complain about crossing initialization - of internal entities. They can't be accessed, - and they should be cleaned up - by the time we get to the label. */ - && ! DECL_ARTIFICIAL (new_decls) - && ((DECL_INITIAL (new_decls) != NULL_TREE - && DECL_INITIAL (new_decls) != error_mark_node) - || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) - { - if (! identified) - error ("jump to case label"); - identified = 1; - cp_error_at (" crosses initialization of `%#D'", - new_decls); - } - } + tree label; + + /* For templates, just add the case label; we'll do semantic + analysis at instantiation-time. */ + label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + return add_stmt (build_case_label (low_value, high_value, label)); } - /* After labels, make any new cleanups go into their + /* Find the condition on which this switch statement depends. */ + cond = SWITCH_COND (switch_stack->switch_stmt); + if (cond && TREE_CODE (cond) == TREE_LIST) + cond = TREE_VALUE (cond); + + r = c_add_case_label (switch_stack->cases, cond, low_value, high_value); + if (r == error_mark_node) + r = NULL_TREE; + + check_switch_goto (switch_stack->level); + + /* After labels, make any new cleanups in the function go into their own new (temporary) binding contour. */ + for (p = current_binding_level; !(p->parm_flag); p = p->level_chain) + p->more_cleanups_ok = 0; - current_binding_level->more_cleanups_ok = 0; - current_function_return_value = NULL_TREE; + return r; } /* Return the list of declarations of the current level. @@ -5150,9 +5322,9 @@ lookup_tag (form, name, binding_level, thislevel_only) int thislevel_only; { register struct binding_level *level; - /* Non-zero if, we should look past a pseudo-global level, even if - THISLEVEL_ONLY. */ - int allow_pseudo_global = 1; + /* Non-zero if, we should look past a template parameter level, even + if THISLEVEL_ONLY. */ + int allow_template_parms_p = 1; for (level = binding_level; level; level = level->level_chain) { @@ -5171,15 +5343,15 @@ lookup_tag (form, name, binding_level, thislevel_only) { tree old = binding_for_name (name, tail); - /* If we just skipped past a pseudo global level, even - though THISLEVEL_ONLY, and we find a template class - declaration, then we use the _TYPE node for the + /* If we just skipped past a template parameter level, + even though THISLEVEL_ONLY, and we find a template + class declaration, then we use the _TYPE node for the template. See the example below. */ - if (thislevel_only && !allow_pseudo_global - && old && BINDING_VALUE (old) + if (thislevel_only && !allow_template_parms_p + && old && BINDING_VALUE (old) && DECL_CLASS_TEMPLATE_P (BINDING_VALUE (old))) old = TREE_TYPE (BINDING_VALUE (old)); - else + else old = BINDING_TYPE (old); /* If it has an original type, it is a typedef, and we @@ -5189,7 +5361,7 @@ lookup_tag (form, name, binding_level, thislevel_only) if (old && TREE_CODE (old) != form && !(form != ENUMERAL_TYPE && TREE_CODE (old) == TEMPLATE_DECL)) { - cp_error ("`%#D' redeclared as %C", old, form); + error ("`%#D' redeclared as %C", old, form); return NULL_TREE; } if (old) @@ -5209,7 +5381,7 @@ lookup_tag (form, name, binding_level, thislevel_only) && !(form != ENUMERAL_TYPE && code == TEMPLATE_DECL)) { /* Definition isn't the kind we were looking for. */ - cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail), + error ("`%#D' redeclared as %C", TREE_VALUE (tail), form); return NULL_TREE; } @@ -5218,78 +5390,25 @@ lookup_tag (form, name, binding_level, thislevel_only) } if (thislevel_only && ! level->tag_transparent) { - if (level->pseudo_global && allow_pseudo_global) + if (level->template_parms_p && allow_template_parms_p) { /* We must deal with cases like this: - + template <class T> struct S; template <class T> struct S {}; - + When looking up `S', for the second declaration, we would like to find the first declaration. But, we are in the pseudo-global level created for the template parameters, rather than the (surrounding) namespace level. Thus, we keep going one more level, even though THISLEVEL_ONLY is non-zero. */ - allow_pseudo_global = 0; + allow_template_parms_p = 0; continue; } else return NULL_TREE; } - if (current_class_type && level->level_chain->namespace_p) - { - /* Try looking in this class's tags before heading into - global binding level. */ - tree context = current_class_type; - while (context) - { - switch (TREE_CODE_CLASS (TREE_CODE (context))) - { - tree these_tags; - case 't': - these_tags = CLASSTYPE_TAGS (context); - if (ANON_AGGRNAME_P (name)) - while (these_tags) - { - if (TYPE_IDENTIFIER (TREE_VALUE (these_tags)) - == name) - return TREE_VALUE (tail); - these_tags = TREE_CHAIN (these_tags); - } - else - while (these_tags) - { - if (TREE_PURPOSE (these_tags) == name) - { - if (TREE_CODE (TREE_VALUE (these_tags)) != form) - { - cp_error ("`%#D' redeclared as %C in class scope", - TREE_VALUE (tail), form); - return NULL_TREE; - } - return TREE_VALUE (tail); - } - these_tags = TREE_CHAIN (these_tags); - } - /* If this type is not yet complete, then don't - look at its context. */ - if (TYPE_SIZE (context) == NULL_TREE) - goto no_context; - /* Go to next enclosing type, if any. */ - context = DECL_CONTEXT (TYPE_MAIN_DECL (context)); - break; - case 'd': - context = DECL_CONTEXT (context); - break; - default: - my_friendly_abort (10); - } - continue; - no_context: - break; - } - } } return NULL_TREE; } @@ -5333,56 +5452,14 @@ lookup_tag_reverse (type, name) return NULL_TREE; } -/* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). - Return the type value, or NULL_TREE if not found. */ - -static tree -lookup_nested_type (type, context) - tree type; - tree context; -{ - if (context == NULL_TREE) - return NULL_TREE; - while (context) - { - switch (TREE_CODE (context)) - { - case TYPE_DECL: - { - tree ctype = TREE_TYPE (context); - tree match = value_member (type, CLASSTYPE_TAGS (ctype)); - if (match) - return TREE_VALUE (match); - context = DECL_CONTEXT (context); - - /* When we have a nested class whose member functions have - local types (e.g., a set of enums), we'll arrive here - with the DECL_CONTEXT as the actual RECORD_TYPE node for - the enclosing class. Instead, we want to make sure we - come back in here with the TYPE_DECL, not the RECORD_TYPE. */ - if (context && TREE_CODE (context) == RECORD_TYPE) - context = TREE_CHAIN (context); - } - break; - case FUNCTION_DECL: - if (TYPE_NAME (type) && TYPE_IDENTIFIER (type)) - return lookup_name (TYPE_IDENTIFIER (type), 1); - return NULL_TREE; - default: - my_friendly_abort (12); - } - } - return NULL_TREE; -} - /* Look up NAME in the NAMESPACE. */ tree lookup_namespace_name (namespace, name) tree namespace, name; { - struct tree_binding _b; tree val; + tree template_id = NULL_TREE; my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 370); @@ -5393,15 +5470,25 @@ lookup_namespace_name (namespace, name) { /* This happens for A::B where B is a template, and there are no template arguments. */ - cp_error ("invalid use of `%D'", name); + error ("invalid use of `%D'", name); return error_mark_node; } namespace = ORIGINAL_NAMESPACE (namespace); + if (TREE_CODE (name) == TEMPLATE_ID_EXPR) + { + template_id = name; + name = TREE_OPERAND (name, 0); + if (TREE_CODE (name) == OVERLOAD) + name = DECL_NAME (OVL_CURRENT (name)); + else if (DECL_P (name)) + name = DECL_NAME (name); + } + my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 373); - - val = binding_init (&_b); + + val = make_node (CPLUS_BINDING); if (!qualified_lookup_using_namespace (name, namespace, val, 0)) return error_mark_node; @@ -5409,13 +5496,34 @@ lookup_namespace_name (namespace, name) { val = BINDING_VALUE (val); + if (template_id) + { + if (DECL_CLASS_TEMPLATE_P (val)) + val = lookup_template_class (val, + TREE_OPERAND (template_id, 1), + /*in_decl=*/NULL_TREE, + /*context=*/NULL_TREE, + /*entering_scope=*/0, + /*complain=*/1); + else if (DECL_FUNCTION_TEMPLATE_P (val) + || TREE_CODE (val) == OVERLOAD) + val = lookup_template_function (val, + TREE_OPERAND (template_id, 1)); + else + { + error ("`%D::%D' is not a template", + namespace, name); + return error_mark_node; + } + } + /* If we have a single function from a using decl, pull it out. */ if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val)) val = OVL_FUNCTION (val); return val; } - cp_error ("`%D' undeclared in namespace `%D'", name, namespace); + error ("`%D' undeclared in namespace `%D'", name, namespace); return error_mark_node; } @@ -5437,7 +5545,7 @@ typename_hash (k) /* Compare two TYPENAME_TYPEs. K1 and K2 are really of type `tree'. */ -static boolean +static bool typename_compare (k1, k2) hash_table_key k1; hash_table_key k2; @@ -5451,10 +5559,10 @@ typename_compare (k1, k2) t2 = (tree) k2; d1 = TYPE_NAME (t1); d2 = TYPE_NAME (t2); - + return (DECL_NAME (d1) == DECL_NAME (d2) && same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)) - && ((TREE_TYPE (t1) != NULL_TREE) + && ((TREE_TYPE (t1) != NULL_TREE) == (TREE_TYPE (t2) != NULL_TREE)) && same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) && TYPENAME_TYPE_FULLNAME (t1) == TYPENAME_TYPE_FULLNAME (t2)); @@ -5464,7 +5572,7 @@ typename_compare (k1, k2) the type of `T', NAME is the IDENTIFIER_NODE for `t'. If BASE_TYPE is non-NULL, this type is being created by the implicit typename extension, and BASE_TYPE is a type named `t' in some base class of - `T' which depends on template parameters. + `T' which depends on template parameters. Returns the new TYPENAME_TYPE. */ @@ -5477,24 +5585,20 @@ build_typename_type (context, name, fullname, base_type) { tree t; tree d; - struct hash_entry* e; + struct hash_entry *e; static struct hash_table ht; - push_obstacks (&permanent_obstack, &permanent_obstack); - - if (!ht.table - && !hash_table_init (&ht, &hash_newfunc, &typename_hash, - &typename_compare)) - fatal ("virtual memory exhausted"); + if (!ht.table) + { + static struct hash_table *h = &ht; - /* The FULLNAME needs to exist for the life of the hash table, i.e., - for the entire compilation. */ - if (!TREE_PERMANENT (fullname)) - fullname = copy_to_permanent (fullname); + hash_table_init (&ht, &hash_newfunc, &typename_hash, &typename_compare); + ggc_add_tree_hash_table_root (&h, 1); + } /* Build the TYPENAME_TYPE. */ - t = make_lang_type (TYPENAME_TYPE); + t = make_aggr_type (TYPENAME_TYPE); TYPE_CONTEXT (t) = FROB_CONTEXT (context); TYPENAME_TYPE_FULLNAME (t) = fullname; TREE_TYPE (t) = base_type; @@ -5509,32 +5613,29 @@ build_typename_type (context, name, fullname, base_type) /* See if we already have this type. */ e = hash_lookup (&ht, t, /*create=*/false, /*copy=*/0); if (e) - { - /* This will free not only TREE_TYPE, but the lang-specific data - and the TYPE_DECL as well. */ - obstack_free (&permanent_obstack, t); - t = (tree) e->key; - } + t = (tree) e->key; else /* Insert the type into the table. */ hash_lookup (&ht, t, /*create=*/true, /*copy=*/0); - pop_obstacks (); - return t; } +/* Resolve `typename CONTEXT::NAME'. Returns an appropriate type, + unless an error occurs, in which case error_mark_node is returned. + If COMPLAIN zero, don't complain about any errors that occur. */ + tree -make_typename_type (context, name) +make_typename_type (context, name, complain) tree context, name; + int complain; { - tree t; tree fullname; - if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') + if (TYPE_P (name)) { - if (!(TYPE_LANG_SPECIFIC (name) - && (CLASSTYPE_IS_TEMPLATE (name) + if (!(TYPE_LANG_SPECIFIC (name) + && (CLASSTYPE_IS_TEMPLATE (name) || CLASSTYPE_USE_TEMPLATE (name)))) name = TYPE_IDENTIFIER (name); else @@ -5554,15 +5655,21 @@ make_typename_type (context, name) if (TREE_CODE (name) == TEMPLATE_DECL) name = TREE_OPERAND (fullname, 0) = DECL_NAME (name); } + if (TREE_CODE (name) == TEMPLATE_DECL) + { + error ("`%D' used without template parameters", name); + return error_mark_node; + } if (TREE_CODE (name) != IDENTIFIER_NODE) - my_friendly_abort (2000); + abort (); if (TREE_CODE (context) == NAMESPACE_DECL) { /* We can get here from typename_sub0 in the explicit_template_type expansion. Just fail. */ - cp_error ("no class template named `%#T' in `%#T'", - name, context); + if (complain) + error ("no class template named `%#T' in `%#T'", + name, context); return error_mark_node; } @@ -5576,26 +5683,30 @@ make_typename_type (context, name) tmpl = lookup_field (context, name, 0, 0); if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl)) { - cp_error ("no class template named `%#T' in `%#T'", - name, context); + if (complain) + error ("no class template named `%#T' in `%#T'", + name, context); return error_mark_node; } - return lookup_template_class (tmpl, + return lookup_template_class (tmpl, TREE_OPERAND (fullname, 1), - NULL_TREE, context, - /*entering_scope=*/0); + NULL_TREE, context, + /*entering_scope=*/0, + /*complain=*/1); } else { - if (IS_AGGR_TYPE (context)) - t = lookup_field (context, name, 0, 1); - else + tree t; + + if (!IS_AGGR_TYPE (context)) { - cp_error ("no type named `%#T' in `%#T'", name, context); + if (complain) + error ("no type named `%#T' in `%#T'", name, context); return error_mark_node; } + t = lookup_field (context, name, 0, 1); if (t) return TREE_TYPE (t); } @@ -5603,16 +5714,72 @@ make_typename_type (context, name) /* If the CONTEXT is not a template type, then either the field is there now or its never going to be. */ - if (!uses_template_parms (context) && !t) + if (!uses_template_parms (context)) { - cp_error ("no type named `%#T' in `%#T'", name, context); + if (complain) + error ("no type named `%#T' in `%#T'", name, context); return error_mark_node; } - - + + return build_typename_type (context, name, fullname, NULL_TREE); } +/* Resolve `CONTEXT::template NAME'. Returns an appropriate type, + unless an error occurs, in which case error_mark_node is returned. + If COMPLAIN zero, don't complain about any errors that occur. */ + +tree +make_unbound_class_template (context, name, complain) + tree context, name; + int complain; +{ + tree t; + tree d; + + if (TYPE_P (name)) + name = TYPE_IDENTIFIER (name); + else if (DECL_P (name)) + name = DECL_NAME (name); + if (TREE_CODE (name) != IDENTIFIER_NODE) + abort (); + + if (!uses_template_parms (context) + || currently_open_class (context)) + { + tree tmpl = NULL_TREE; + + if (IS_AGGR_TYPE (context)) + tmpl = lookup_field (context, name, 0, 0); + + if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl)) + { + if (complain) + error ("no class template named `%#T' in `%#T'", name, context); + return error_mark_node; + } + + if (!enforce_access (context, tmpl)) + return error_mark_node; + + return tmpl; + } + + /* Build the UNBOUND_CLASS_TEMPLATE. */ + t = make_aggr_type (UNBOUND_CLASS_TEMPLATE); + TYPE_CONTEXT (t) = FROB_CONTEXT (context); + TREE_TYPE (t) = NULL_TREE; + + /* Build the corresponding TEMPLATE_DECL. */ + d = build_decl (TEMPLATE_DECL, name, t); + TYPE_NAME (TREE_TYPE (d)) = d; + TYPE_STUB_DECL (TREE_TYPE (d)) = d; + DECL_CONTEXT (d) = FROB_CONTEXT (context); + DECL_ARTIFICIAL (d) = 1; + + return t; +} + /* Select the right _DECL from multiple choices. */ static tree @@ -5622,6 +5789,15 @@ select_decl (binding, flags) { tree val; val = BINDING_VALUE (binding); + + /* When we implicitly declare some builtin entity, we mark it + DECL_ANTICIPATED, so that we know to ignore it until it is + really declared. */ + if (val && DECL_P (val) + && DECL_LANG_SPECIFIC (val) + && DECL_ANTICIPATED (val)) + return NULL_TREE; + if (LOOKUP_NAMESPACES_ONLY (flags)) { /* We are not interested in types. */ @@ -5629,7 +5805,7 @@ select_decl (binding, flags) return val; return NULL_TREE; } - + /* If we could have a type and we have nothing or we need a type and have none. */ if (BINDING_TYPE (binding) @@ -5645,24 +5821,30 @@ select_decl (binding, flags) return val; } -/* Unscoped lookup of a global, iterate over namespaces, considering - using namespace statements. */ +/* Unscoped lookup of a global: iterate over current namespaces, + considering using-directives. If SPACESP is non-NULL, store a list + of the namespaces we've considered in it. */ -static tree -unqualified_namespace_lookup (name, flags) +tree +unqualified_namespace_lookup (name, flags, spacesp) tree name; int flags; + tree *spacesp; { - struct tree_binding _binding; - tree b = binding_init (&_binding); - tree initial = current_decl_namespace(); + tree b = make_node (CPLUS_BINDING); + tree initial = current_decl_namespace (); tree scope = initial; tree siter; struct binding_level *level; tree val = NULL_TREE; - while (!val) + if (spacesp) + *spacesp = NULL_TREE; + + for (; !val; scope = CP_DECL_CONTEXT (scope)) { + if (spacesp) + *spacesp = tree_cons (scope, NULL_TREE, *spacesp); val = binding_for_name (name, scope); /* Initialize binding for this context. */ @@ -5670,11 +5852,11 @@ unqualified_namespace_lookup (name, flags) BINDING_TYPE (b) = BINDING_TYPE (val); /* Add all _DECLs seen through local using-directives. */ - for (level = current_binding_level; + for (level = current_binding_level; !level->namespace_p; level = level->level_chain) if (!lookup_using_namespace (name, b, level->using_directives, - scope, flags)) + scope, flags, spacesp)) /* Give up because of error. */ return error_mark_node; @@ -5683,8 +5865,8 @@ unqualified_namespace_lookup (name, flags) siter = initial; while (1) { - if (!lookup_using_namespace (name, b, DECL_NAMESPACE_USING (siter), - scope, flags)) + if (!lookup_using_namespace (name, b, DECL_NAMESPACE_USING (siter), + scope, flags, spacesp)) /* Give up because of error. */ return error_mark_node; if (siter == scope) break; @@ -5694,7 +5876,6 @@ unqualified_namespace_lookup (name, flags) val = select_decl (b, flags); if (scope == global_namespace) break; - scope = CP_DECL_CONTEXT (scope); } return val; } @@ -5753,11 +5934,11 @@ warn_about_implicit_typename_lookup (typename, binding) && ! (TREE_CODE (binding) == TYPE_DECL && same_type_p (TREE_TYPE (binding), subtype))) { - cp_warning ("lookup of `%D' finds `%#D'", + warning ("lookup of `%D' finds `%#D'", name, binding); - cp_warning (" instead of `%D' from dependent base class", + warning (" instead of `%D' from dependent base class", typename); - cp_warning (" (use `typename %T::%D' if that's what you meant)", + warning (" (use `typename %T::%D' if that's what you meant)", constructor_name (current_class_type), name); } } @@ -5771,7 +5952,7 @@ warn_about_implicit_typename_lookup (typename, binding) If PREFER_TYPE is > 0, we prefer TYPE_DECLs or namespaces. If PREFER_TYPE is > 1, we reject non-type decls (e.g. namespaces). If PREFER_TYPE is -2, we're being called from yylex(). (UGLY) - Otherwise we prefer non-TYPE_DECLs. + Otherwise we prefer non-TYPE_DECLs. If NONCLASS is non-zero, we don't look for the NAME in class scope, using IDENTIFIER_CLASS_VALUE. */ @@ -5805,15 +5986,11 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) if (looking_for_template) flags |= LOOKUP_TEMPLATES_EXPECTED; - /* std:: becomes :: for now. */ - if (got_scope == std_node) - got_scope = void_type_node; - if (got_scope) type = got_scope; else if (got_object != error_mark_node) type = got_object; - + if (type) { if (type == error_mark_node) @@ -5828,8 +6005,7 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) type = global_namespace; if (TREE_CODE (type) == NAMESPACE_DECL) { - struct tree_binding b; - val = binding_init (&b); + val = make_node (CPLUS_BINDING); flags |= LOOKUP_COMPLAIN; if (!qualified_lookup_using_namespace (name, type, val, flags)) return NULL_TREE; @@ -5837,14 +6013,24 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) } else if (! IS_AGGR_TYPE (type) || TREE_CODE (type) == TEMPLATE_TYPE_PARM - || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM + || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM || TREE_CODE (type) == TYPENAME_TYPE) /* Someone else will give an error about this if needed. */ val = NULL_TREE; else if (type == current_class_type) val = IDENTIFIER_CLASS_VALUE (name); else - val = lookup_member (type, name, 0, prefer_type); + { + val = lookup_member (type, name, 0, prefer_type); + type_access_control (type, val); + + /* Restore the containing TYPENAME_TYPE if we looked + through it before. */ + if (got_scope && got_scope != type + && val && TREE_CODE (val) == TYPE_DECL + && TREE_CODE (TREE_TYPE (val)) == TYPENAME_TYPE) + TYPE_CONTEXT (TREE_TYPE (val)) = got_scope; + } } else val = NULL_TREE; @@ -5852,7 +6038,10 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) if (got_scope) goto done; else if (got_object && val) - from_obj = val; + { + from_obj = val; + val = NULL_TREE; + } } else { @@ -5862,6 +6051,10 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) } /* First, look in non-namespace scopes. */ + + if (current_class_type == NULL_TREE) + nonclass = 1; + for (t = IDENTIFIER_BINDING (name); t; t = TREE_CHAIN (t)) { tree binding; @@ -5869,26 +6062,29 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) if (!LOCAL_BINDING_P (t) && nonclass) /* We're not looking for class-scoped bindings, so keep going. */ continue; - + /* If this is the kind of thing we're looking for, we're done. */ if (qualify_lookup (BINDING_VALUE (t), flags)) binding = BINDING_VALUE (t); - else if ((flags & LOOKUP_PREFER_TYPES) + else if ((flags & LOOKUP_PREFER_TYPES) && qualify_lookup (BINDING_TYPE (t), flags)) binding = BINDING_TYPE (t); else binding = NULL_TREE; + /* Handle access control on types from enclosing or base classes. */ + if (binding && ! yylex + && BINDING_LEVEL (t) && BINDING_LEVEL (t)->parm_flag == 2) + type_access_control (BINDING_LEVEL (t)->this_class, binding); + if (binding - && (!val || !(TREE_CODE (binding) == TYPE_DECL - && IMPLICIT_TYPENAME_P (TREE_TYPE (binding))))) + && (!val || !IMPLICIT_TYPENAME_TYPE_DECL_P (binding))) { if (val_is_implicit_typename && !yylex) warn_about_implicit_typename_lookup (val, binding); val = binding; - val_is_implicit_typename - = (TREE_CODE (val) == TYPE_DECL - && IMPLICIT_TYPENAME_P (TREE_TYPE (val))); + val_is_implicit_typename + = IMPLICIT_TYPENAME_TYPE_DECL_P (val); if (!val_is_implicit_typename) break; } @@ -5897,7 +6093,7 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) /* Now lookup in namespace scopes. */ if (!val || val_is_implicit_typename) { - t = unqualified_namespace_lookup (name, flags); + t = unqualified_namespace_lookup (name, flags, 0); if (t) { if (val_is_implicit_typename && !yylex) @@ -5914,13 +6110,11 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only) { if (looking_for_typename && TREE_CODE (from_obj) == TYPE_DECL && TREE_CODE (val) == TYPE_DECL - && TREE_TYPE (from_obj) != TREE_TYPE (val)) - { - cp_pedwarn ("lookup of `%D' in the scope of `%#T' (`%#T')", - name, got_object, TREE_TYPE (from_obj)); - cp_pedwarn (" does not match lookup in the current scope (`%#T')", - TREE_TYPE (val)); - } + && ! same_type_p (TREE_TYPE (from_obj), TREE_TYPE (val))) + pedwarn ("\ +lookup of `%D' in the scope of `%#T' (`%#D') \ +does not match lookup in the current scope (`%#D')", + name, got_object, from_obj, val); /* We don't change val to from_obj if got_object depends on template parms because that breaks implicit typename for @@ -5986,20 +6180,20 @@ lookup_name_current_level (name) if (b->namespace_p) { - t = IDENTIFIER_NAMESPACE_VALUE (name); + t = IDENTIFIER_NAMESPACE_VALUE (name); /* extern "C" function() */ if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST) t = TREE_VALUE (t); } - else if (IDENTIFIER_BINDING (name) + else if (IDENTIFIER_BINDING (name) && LOCAL_BINDING_P (IDENTIFIER_BINDING (name))) { while (1) { if (BINDING_LEVEL (IDENTIFIER_BINDING (name)) == b) return IDENTIFIER_VALUE (name); - + if (b->keep == 2) b = b->level_chain; else @@ -6050,47 +6244,12 @@ end_only_namespace_names () only_namespace_names = 0; } -/* Arrange for the user to get a source line number, even when the - compiler is going down in flames, so that she at least has a - chance of working around problems in the compiler. We used to - call error(), but that let the segmentation fault continue - through; now, it's much more passive by asking them to send the - maintainers mail about the problem. */ - -static void -signal_catch (sig) - int sig ATTRIBUTE_UNUSED; -{ - signal (SIGSEGV, SIG_DFL); -#ifdef SIGIOT - signal (SIGIOT, SIG_DFL); -#endif -#ifdef SIGILL - signal (SIGILL, SIG_DFL); -#endif -#ifdef SIGABRT - signal (SIGABRT, SIG_DFL); -#endif -#ifdef SIGBUS - signal (SIGBUS, SIG_DFL); -#endif - my_friendly_abort (0); -} - -#if 0 -/* Unused -- brendan 970107 */ -/* Array for holding types considered "built-in". These types - are output in the module in which `main' is defined. */ -static tree *builtin_type_tdescs_arr; -static int builtin_type_tdescs_len, builtin_type_tdescs_max; -#endif - /* Push the declarations of builtin types into the namespace. - RID_INDEX, if < RID_MAX is the index of the builtin type + RID_INDEX is the index of the builtin type in the array RID_POINTERS. NAME is the name used when looking up the builtin type. TYPE is the _TYPE node for the builtin type. */ -static void +void record_builtin_type (rid_index, name, type) enum rid rid_index; const char *name; @@ -6105,7 +6264,7 @@ record_builtin_type (rid_index, name, type) tname = get_identifier (name); TYPE_BUILT_IN (type) = 1; - + if (tname) { tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); @@ -6178,31 +6337,59 @@ record_unknown_type (type, name) TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; TYPE_SIZE (type) = TYPE_SIZE (void_type_node); TYPE_ALIGN (type) = 1; + TYPE_USER_ALIGN (type) = 0; TYPE_MODE (type) = TYPE_MODE (void_type_node); -} +} -/* Push overloaded decl, in global scope, with one argument so it - can be used as a callback from define_function. */ +/* An string for which we should create an IDENTIFIER_NODE at + startup. */ -static void -push_overloaded_decl_1 (x) - tree x; +typedef struct predefined_identifier { - push_overloaded_decl (x, PUSH_GLOBAL); -} + /* The name of the identifier. */ + const char *const name; + /* The place where the IDENTIFIER_NODE should be stored. */ + tree *const node; + /* Non-zero if this is the name of a constructor or destructor. */ + const int ctor_or_dtor_p; +} predefined_identifier; -#ifdef __GNUC__ -__inline -#endif -tree -auto_function (name, type, code) - tree name, type; - enum built_in_function code; -{ - return define_function - (IDENTIFIER_POINTER (name), type, code, push_overloaded_decl_1, - IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type), - 0))); +/* Create all the predefined identifiers. */ + +static void +initialize_predefined_identifiers () +{ + const predefined_identifier *pid; + + /* A table of identifiers to create at startup. */ + static const predefined_identifier predefined_identifiers[] = { + { "C++", &lang_name_cplusplus, 0 }, + { "C", &lang_name_c, 0 }, + { "Java", &lang_name_java, 0 }, + { CTOR_NAME, &ctor_identifier, 1 }, + { "__base_ctor", &base_ctor_identifier, 1 }, + { "__comp_ctor", &complete_ctor_identifier, 1 }, + { DTOR_NAME, &dtor_identifier, 1 }, + { "__comp_dtor", &complete_dtor_identifier, 1 }, + { "__base_dtor", &base_dtor_identifier, 1 }, + { "__deleting_dtor", &deleting_dtor_identifier, 1 }, + { IN_CHARGE_NAME, &in_charge_identifier, 0 }, + { "nelts", &nelts_identifier, 0 }, + { THIS_NAME, &this_identifier, 0 }, + { VTABLE_DELTA_NAME, &delta_identifier, 0 }, + { VTABLE_PFN_NAME, &pfn_identifier, 0 }, + { "_vptr", &vptr_identifier, 0 }, + { "__vtt_parm", &vtt_parm_identifier, 0 }, + { "std", &std_identifier, 0 }, + { NULL, NULL, 0 } + }; + + for (pid = predefined_identifiers; pid->name; ++pid) + { + *pid->node = get_identifier (pid->name); + if (pid->ctor_or_dtor_p) + IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1; + } } /* Create the predefined scalar types of C, @@ -6211,79 +6398,62 @@ auto_function (name, type, code) Make definitions for built-in primitive functions. */ void -init_decl_processing () -{ - register tree endlink, int_endlink, double_endlink, unsigned_endlink; - tree fields[20]; - /* Data type of memcpy. */ - tree memcpy_ftype, strlen_ftype; - int wchar_type_size; - tree temp; - tree array_domain_type; - tree vb_off_identifier = NULL_TREE; - /* Function type `char *(char *, char *)' and similar ones */ - tree string_ftype_ptr_ptr, int_ftype_string_string; - tree sizetype_endlink; - tree ptr_ftype, ptr_ftype_unsigned, ptr_ftype_sizetype; - tree void_ftype, void_ftype_int, void_ftype_ptr; - - /* Have to make these distinct before we try using them. */ - lang_name_cplusplus = get_identifier ("C++"); - lang_name_c = get_identifier ("C"); - lang_name_java = get_identifier ("Java"); +cxx_init_decl_processing () +{ + tree void_ftype; + tree void_ftype_ptr; + + /* Create all the identifiers we need. */ + initialize_predefined_identifiers (); + + /* Fill in back-end hooks. */ + init_lang_status = &push_cp_function_context; + free_lang_status = &pop_cp_function_context; + mark_lang_status = &mark_cp_function_context; + lang_missing_noreturn_ok_p = &cp_missing_noreturn_ok_p; + + cp_parse_init (); + init_decl2 (); + init_pt (); + + /* Create the global variables. */ + push_to_top_level (); /* Enter the global namespace. */ my_friendly_assert (global_namespace == NULL_TREE, 375); - my_friendly_assert (current_lang_name == NULL_TREE, 375); - current_lang_name = lang_name_cplusplus; push_namespace (get_identifier ("::")); global_namespace = current_namespace; current_lang_name = NULL_TREE; - if (flag_strict_prototype == 2) - flag_strict_prototype = pedantic; + /* Adjust various flags based on command-line settings. */ if (! flag_permissive && ! pedantic) flag_pedantic_errors = 1; + if (!flag_no_inline) + { + flag_inline_trees = 1; + flag_no_inline = 1; + } + if (flag_inline_functions) + { + flag_inline_trees = 2; + flag_inline_functions = 0; + } - strict_prototypes_lang_c = flag_strict_prototype; + /* In C++, we never create builtin functions whose name does not + begin with `__'. Users should be using headers to get prototypes + in C++. It would be nice if we could warn when `-fbuiltin' is + used explicitly, but we do not have that information. */ + flag_no_builtin = 1; /* Initially, C. */ current_lang_name = lang_name_c; current_function_decl = NULL_TREE; - named_labels = NULL_TREE; - named_label_uses = NULL; current_binding_level = NULL_BINDING_LEVEL; free_binding_level = NULL_BINDING_LEVEL; - /* Because most segmentation signals can be traced back into user - code, catch them and at least give the user a chance of working - around compiler bugs. */ - signal (SIGSEGV, signal_catch); - - /* We will also catch aborts in the back-end through signal_catch and - give the user a chance to see where the error might be, and to defeat - aborts in the back-end when there have been errors previously in their - code. */ -#ifdef SIGIOT - signal (SIGIOT, signal_catch); -#endif -#ifdef SIGILL - signal (SIGILL, signal_catch); -#endif -#ifdef SIGABRT - signal (SIGABRT, signal_catch); -#endif -#ifdef SIGBUS - signal (SIGBUS, signal_catch); -#endif - - gcc_obstack_init (&decl_obstack); + build_common_tree_nodes (flag_signed_char); - /* Must lay these out before anything else gets laid out. */ - error_mark_node = make_node (ERROR_MARK); - TREE_PERMANENT (error_mark_node) = 1; - TREE_TYPE (error_mark_node) = error_mark_node; error_mark_list = build_tree_list (error_mark_node, error_mark_node); TREE_TYPE (error_mark_list) = error_mark_node; @@ -6294,147 +6464,14 @@ init_decl_processing () NAMESPACE_LEVEL (global_namespace) = global_binding_level; declare_namespace_level (); - this_identifier = get_identifier (THIS_NAME); - in_charge_identifier = get_identifier (IN_CHARGE_NAME); - vlist_identifier = get_identifier (VLIST_NAME); - ctor_identifier = get_identifier (CTOR_NAME); - dtor_identifier = get_identifier (DTOR_NAME); - pfn_identifier = get_identifier (VTABLE_PFN_NAME); - index_identifier = get_identifier (VTABLE_INDEX_NAME); - delta_identifier = get_identifier (VTABLE_DELTA_NAME); - delta2_identifier = get_identifier (VTABLE_DELTA2_NAME); - pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2"); - if (flag_handle_signatures) - { - tag_identifier = get_identifier (SIGTABLE_TAG_NAME); - vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME); - vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME); - } - - /* Define `int' and `char' first so that dbx will output them first. */ - - integer_type_node = make_signed_type (INT_TYPE_SIZE); - record_builtin_type (RID_INT, NULL_PTR, integer_type_node); + /* Create the `std' namespace. */ + push_namespace (std_identifier); + std_node = current_namespace; + pop_namespace (); - /* Define `char', which is like either `signed char' or `unsigned char' - but not the same as either. */ + lang_attribute_table = cp_attribute_table; - char_type_node - = (flag_signed_char - ? make_signed_type (CHAR_TYPE_SIZE) - : make_unsigned_type (CHAR_TYPE_SIZE)); - record_builtin_type (RID_CHAR, "char", char_type_node); - - /* `signed' is the same as `int' */ - record_builtin_type (RID_SIGNED, NULL_PTR, integer_type_node); - - long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); - record_builtin_type (RID_LONG, "long int", long_integer_type_node); - - unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); - record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); - - long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); - record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node); - record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); - - long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); - record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node); - - long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); - record_builtin_type (RID_MAX, "long long unsigned int", - long_long_unsigned_type_node); - record_builtin_type (RID_MAX, "long long unsigned", - long_long_unsigned_type_node); - - short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); - record_builtin_type (RID_SHORT, "short int", short_integer_type_node); - short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); - record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); - record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); - - /* `unsigned long' is the standard type for sizeof. - Note that stddef.h uses `unsigned long', - and this must agree, even if long and int are the same size. */ - set_sizetype - (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)))); - - ptrdiff_type_node - = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); - - /* Define both `signed char' and `unsigned char'. */ - signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); - record_builtin_type (RID_MAX, "signed char", signed_char_type_node); - unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); - record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); - - /* These are types that type_for_size and type_for_mode use. */ - intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); - pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); - intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); - pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); - intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); - pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); - intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); - pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); -#if HOST_BITS_PER_WIDE_INT >= 64 - intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode)); - pushdecl (build_decl (TYPE_DECL, get_identifier ("__int128_t"), intTI_type_node)); -#endif - unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); - pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); - unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); - pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); - unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); - pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); - unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); - pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); -#if HOST_BITS_PER_WIDE_INT >= 64 - unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode)); - pushdecl (build_decl (TYPE_DECL, get_identifier ("__uint128_t"), unsigned_intTI_type_node)); -#endif - - float_type_node = make_node (REAL_TYPE); - TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; - record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node); - layout_type (float_type_node); - - double_type_node = make_node (REAL_TYPE); - if (flag_short_double) - TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; - else - TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; - record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node); - layout_type (double_type_node); - - long_double_type_node = make_node (REAL_TYPE); - TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; - record_builtin_type (RID_MAX, "long double", long_double_type_node); - layout_type (long_double_type_node); - - complex_integer_type_node = make_node (COMPLEX_TYPE); - pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"), - complex_integer_type_node)); - TREE_TYPE (complex_integer_type_node) = integer_type_node; - layout_type (complex_integer_type_node); - - complex_float_type_node = make_node (COMPLEX_TYPE); - pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"), - complex_float_type_node)); - TREE_TYPE (complex_float_type_node) = float_type_node; - layout_type (complex_float_type_node); - - complex_double_type_node = make_node (COMPLEX_TYPE); - pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"), - complex_double_type_node)); - TREE_TYPE (complex_double_type_node) = double_type_node; - layout_type (complex_double_type_node); - - complex_long_double_type_node = make_node (COMPLEX_TYPE); - pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"), - complex_long_double_type_node)); - TREE_TYPE (complex_long_double_type_node) = long_double_type_node; - layout_type (complex_long_double_type_node); + c_common_nodes_and_builtins (); java_byte_type_node = record_builtin_java_type ("__java_byte", 8); java_short_type_node = record_builtin_java_type ("__java_short", 16); @@ -6445,10 +6482,6 @@ init_decl_processing () java_char_type_node = record_builtin_java_type ("__java_char", -16); java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1); - integer_zero_node = build_int_2 (0, 0); - TREE_TYPE (integer_zero_node) = integer_type_node; - integer_one_node = build_int_2 (1, 0); - TREE_TYPE (integer_one_node) = integer_type_node; integer_two_node = build_int_2 (2, 0); TREE_TYPE (integer_two_node) = integer_type_node; integer_three_node = build_int_2 (3, 0); @@ -6465,318 +6498,28 @@ init_decl_processing () boolean_true_node = build_int_2 (1, 0); TREE_TYPE (boolean_true_node) = boolean_type_node; - /* These are needed by stor-layout.c. */ - size_zero_node = size_int (0); - size_one_node = size_int (1); - signed_size_zero_node = build_int_2 (0, 0); TREE_TYPE (signed_size_zero_node) = make_signed_type (TYPE_PRECISION (sizetype)); - void_type_node = make_node (VOID_TYPE); - record_builtin_type (RID_VOID, NULL_PTR, void_type_node); - layout_type (void_type_node); /* Uses integer_zero_node. */ - void_list_node = build_tree_list (NULL_TREE, void_type_node); - TREE_PARMLIST (void_list_node) = 1; - - null_pointer_node = build_int_2 (0, 0); - TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); - layout_type (TREE_TYPE (null_pointer_node)); - - /* Used for expressions that do nothing, but are not errors. */ - void_zero_node = build_int_2 (0, 0); - TREE_TYPE (void_zero_node) = void_type_node; - - string_type_node = build_pointer_type (char_type_node); - const_string_type_node - = build_pointer_type (build_qualified_type (char_type_node, - TYPE_QUAL_CONST)); -#if 0 - record_builtin_type (RID_MAX, NULL_PTR, string_type_node); -#endif + empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE); - /* Make a type to be the domain of a few array types - whose domains don't really matter. - 200 is small enough that it always fits in size_t - and large enough that it can hold most function names for the - initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ - array_domain_type = build_index_type (build_int_2 (200, 0)); - - /* Make a type for arrays of characters. - With luck nothing will ever really depend on the length of this - array type. */ - char_array_type_node - = build_array_type (char_type_node, array_domain_type); - /* Likewise for arrays of ints. */ - int_array_type_node - = build_array_type (integer_type_node, array_domain_type); - - /* This is just some anonymous class type. Nobody should ever - need to look inside this envelope. */ - class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE)); - - default_function_type - = build_function_type (integer_type_node, NULL_TREE); - - ptr_type_node = build_pointer_type (void_type_node); - const_ptr_type_node - = build_pointer_type (build_qualified_type (void_type_node, - TYPE_QUAL_CONST)); #if 0 - record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node); + record_builtin_type (RID_MAX, NULL, string_type_node); #endif - endlink = void_list_node; - int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); - double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); - unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink); + delta_type_node = ptrdiff_type_node; + vtable_index_type = ptrdiff_type_node; - ptr_ftype = build_function_type (ptr_type_node, NULL_TREE); - ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink); - sizetype_endlink = tree_cons (NULL_TREE, sizetype, endlink); - /* We realloc here because sizetype could be int or unsigned. S'ok. */ - ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink); + vtt_parm_type = build_pointer_type (const_ptr_type_node); + lang_type_promotes_to = convert_type_from_ellipsis; - void_ftype = build_function_type (void_type_node, endlink); - void_ftype_int = build_function_type (void_type_node, int_endlink); + void_ftype = build_function_type (void_type_node, void_list_node); + void_ftype_ptr = build_function_type (void_type_node, + tree_cons (NULL_TREE, + ptr_type_node, + void_list_node)); void_ftype_ptr - = build_function_type (void_type_node, - tree_cons (NULL_TREE, ptr_type_node, endlink)); - void_ftype_ptr - = build_exception_variant (void_ftype_ptr, - tree_cons (NULL_TREE, NULL_TREE, NULL_TREE)); - - float_ftype_float - = build_function_type (float_type_node, - tree_cons (NULL_TREE, float_type_node, endlink)); - - double_ftype_double - = build_function_type (double_type_node, double_endlink); - - ldouble_ftype_ldouble - = build_function_type (long_double_type_node, - tree_cons (NULL_TREE, long_double_type_node, - endlink)); - - double_ftype_double_double - = build_function_type (double_type_node, - tree_cons (NULL_TREE, double_type_node, - double_endlink)); - - int_ftype_int - = build_function_type (integer_type_node, int_endlink); - - long_ftype_long - = build_function_type (long_integer_type_node, - tree_cons (NULL_TREE, long_integer_type_node, - endlink)); - - int_ftype_cptr_cptr_sizet - = build_function_type (integer_type_node, - tree_cons (NULL_TREE, const_ptr_type_node, - tree_cons (NULL_TREE, const_ptr_type_node, - tree_cons (NULL_TREE, - sizetype, - endlink)))); - - string_ftype_ptr_ptr /* strcpy prototype */ - = build_function_type (string_type_node, - tree_cons (NULL_TREE, string_type_node, - tree_cons (NULL_TREE, - const_string_type_node, - endlink))); - - int_ftype_string_string /* strcmp prototype */ - = build_function_type (integer_type_node, - tree_cons (NULL_TREE, const_string_type_node, - tree_cons (NULL_TREE, - const_string_type_node, - endlink))); - - strlen_ftype /* strlen prototype */ - = build_function_type (sizetype, - tree_cons (NULL_TREE, const_string_type_node, - endlink)); - - memcpy_ftype /* memcpy prototype */ - = build_function_type (ptr_type_node, - tree_cons (NULL_TREE, ptr_type_node, - tree_cons (NULL_TREE, const_ptr_type_node, - sizetype_endlink))); - - if (flag_huge_objects) - delta_type_node = long_integer_type_node; - else - delta_type_node = short_integer_type_node; - - builtin_function ("__builtin_constant_p", default_function_type, - BUILT_IN_CONSTANT_P, NULL_PTR); - - builtin_return_address_fndecl - = builtin_function ("__builtin_return_address", ptr_ftype_unsigned, - BUILT_IN_RETURN_ADDRESS, NULL_PTR); - - builtin_function ("__builtin_frame_address", ptr_ftype_unsigned, - BUILT_IN_FRAME_ADDRESS, NULL_PTR); - - builtin_function ("__builtin_alloca", ptr_ftype_sizetype, - BUILT_IN_ALLOCA, "alloca"); - builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); - /* Define alloca, ffs as builtins. - Declare _exit just to mark it as volatile. */ - if (! flag_no_builtin && !flag_no_nonansi_builtin) - { - temp = builtin_function ("alloca", ptr_ftype_sizetype, - BUILT_IN_ALLOCA, NULL_PTR); - /* Suppress error if redefined as a non-function. */ - DECL_BUILT_IN_NONANSI (temp) = 1; - temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); - /* Suppress error if redefined as a non-function. */ - DECL_BUILT_IN_NONANSI (temp) = 1; - temp = builtin_function ("_exit", void_ftype_int, - NOT_BUILT_IN, NULL_PTR); - TREE_THIS_VOLATILE (temp) = 1; - TREE_SIDE_EFFECTS (temp) = 1; - /* Suppress error if redefined as a non-function. */ - DECL_BUILT_IN_NONANSI (temp) = 1; - } - - builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); - builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS, - NULL_PTR); - builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, - NULL_PTR); - builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, - NULL_PTR); - builtin_function ("__builtin_labs", long_ftype_long, - BUILT_IN_LABS, NULL_PTR); - builtin_function ("__builtin_saveregs", ptr_ftype, - BUILT_IN_SAVEREGS, NULL_PTR); - builtin_function ("__builtin_classify_type", default_function_type, - BUILT_IN_CLASSIFY_TYPE, NULL_PTR); - builtin_function ("__builtin_next_arg", ptr_ftype, - BUILT_IN_NEXT_ARG, NULL_PTR); - builtin_function ("__builtin_args_info", int_ftype_int, - BUILT_IN_ARGS_INFO, NULL_PTR); - builtin_function ("__builtin_setjmp", - build_function_type (integer_type_node, - tree_cons (NULL_TREE, ptr_type_node, - endlink)), - BUILT_IN_SETJMP, NULL_PTR); - builtin_function ("__builtin_longjmp", - build_function_type (integer_type_node, - tree_cons (NULL_TREE, ptr_type_node, - tree_cons (NULL_TREE, - integer_type_node, - endlink))), - BUILT_IN_LONGJMP, NULL_PTR); - - /* Untyped call and return. */ - builtin_function ("__builtin_apply_args", ptr_ftype, - BUILT_IN_APPLY_ARGS, NULL_PTR); - - temp = tree_cons (NULL_TREE, - build_pointer_type (build_function_type (void_type_node, - NULL_TREE)), - tree_cons (NULL_TREE, ptr_ftype_sizetype, NULL_TREE)); - builtin_function ("__builtin_apply", - build_function_type (ptr_type_node, temp), - BUILT_IN_APPLY, NULL_PTR); - builtin_function ("__builtin_return", void_ftype_ptr, - BUILT_IN_RETURN, NULL_PTR); - - /* Currently under experimentation. */ - builtin_function ("__builtin_memcpy", memcpy_ftype, - BUILT_IN_MEMCPY, "memcpy"); - builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, - BUILT_IN_MEMCMP, "memcmp"); - builtin_function ("__builtin_strcmp", int_ftype_string_string, - BUILT_IN_STRCMP, "strcmp"); - builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, - BUILT_IN_STRCPY, "strcpy"); - builtin_function ("__builtin_strlen", strlen_ftype, - BUILT_IN_STRLEN, "strlen"); - builtin_function ("__builtin_sqrtf", float_ftype_float, - BUILT_IN_FSQRT, "sqrtf"); - builtin_function ("__builtin_fsqrt", double_ftype_double, - BUILT_IN_FSQRT, NULL_PTR); - builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble, - BUILT_IN_FSQRT, "sqrtl"); - builtin_function ("__builtin_sinf", float_ftype_float, - BUILT_IN_SIN, "sinf"); - builtin_function ("__builtin_sin", double_ftype_double, - BUILT_IN_SIN, "sin"); - builtin_function ("__builtin_sinl", ldouble_ftype_ldouble, - BUILT_IN_SIN, "sinl"); - builtin_function ("__builtin_cosf", float_ftype_float, - BUILT_IN_COS, "cosf"); - builtin_function ("__builtin_cos", double_ftype_double, - BUILT_IN_COS, "cos"); - builtin_function ("__builtin_cosl", ldouble_ftype_ldouble, - BUILT_IN_COS, "cosl"); - - if (!flag_no_builtin) - { - builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); - builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); - builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); - builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR); - builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, - NULL_PTR); - builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); - builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, - NULL_PTR); - builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, - NULL_PTR); - builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, - NULL_PTR); - builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR); - builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR); - builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR); - builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT, - NULL_PTR); - builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR); - builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); - builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR); - builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR); - builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); - builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR); - - /* Declare these functions volatile - to avoid spurious "control drops through" warnings. */ - temp = builtin_function ("abort", void_ftype, - NOT_BUILT_IN, NULL_PTR); - TREE_THIS_VOLATILE (temp) = 1; - TREE_SIDE_EFFECTS (temp) = 1; - /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on - them... */ - DECL_BUILT_IN_NONANSI (temp) = 1; - temp = builtin_function ("exit", void_ftype_int, - NOT_BUILT_IN, NULL_PTR); - TREE_THIS_VOLATILE (temp) = 1; - TREE_SIDE_EFFECTS (temp) = 1; - DECL_BUILT_IN_NONANSI (temp) = 1; - } - -#if 0 - /* Support for these has not been written in either expand_builtin - or build_function_call. */ - builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR); - builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR); - builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, - NULL_PTR); - builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, - NULL_PTR); - builtin_function ("__builtin_fmod", double_ftype_double_double, - BUILT_IN_FMOD, NULL_PTR); - builtin_function ("__builtin_frem", double_ftype_double_double, - BUILT_IN_FREM, NULL_PTR); - builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, - BUILT_IN_MEMSET, NULL_PTR); - builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, - NULL_PTR); - builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, - NULL_PTR); -#endif + = build_exception_variant (void_ftype_ptr, empty_except_spec); /* C++ extensions */ @@ -6786,136 +6529,35 @@ init_decl_processing () /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ TREE_TYPE (unknown_type_node) = unknown_type_node; - TREE_TYPE (null_node) = type_for_size (POINTER_SIZE, 0); - /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */ TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; - /* This is for handling opaque types in signatures. */ - opaque_type_node = copy_node (ptr_type_node); - TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node; - record_builtin_type (RID_MAX, 0, opaque_type_node); - - /* This is special for C++ so functions can be overloaded. */ - wchar_type_node - = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); - wchar_type_size = TYPE_PRECISION (wchar_type_node); - signed_wchar_type_node = make_signed_type (wchar_type_size); - unsigned_wchar_type_node = make_unsigned_type (wchar_type_size); - wchar_type_node - = TREE_UNSIGNED (wchar_type_node) - ? unsigned_wchar_type_node - : signed_wchar_type_node; - record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node); - - /* Artificial declaration of wchar_t -- can be bashed */ - wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"), - wchar_type_node); - pushdecl (wchar_decl_node); - - /* This is for wide string constants. */ - wchar_array_type_node - = build_array_type (wchar_type_node, array_domain_type); - - if (flag_vtable_thunks) - { - /* Make sure we get a unique function type, so we can give - its pointer type a name. (This wins for gdb.) */ - tree vfunc_type = make_node (FUNCTION_TYPE); - TREE_TYPE (vfunc_type) = integer_type_node; - TYPE_ARG_TYPES (vfunc_type) = NULL_TREE; - layout_type (vfunc_type); - - vtable_entry_type = build_pointer_type (vfunc_type); - } - else - { - vtable_entry_type = make_lang_type (RECORD_TYPE); - fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, - delta_type_node); - fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, - delta_type_node); - fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, - ptr_type_node); - finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2, - double_type_node); - - /* Make this part of an invisible union. */ - fields[3] = copy_node (fields[2]); - TREE_TYPE (fields[3]) = delta_type_node; - DECL_NAME (fields[3]) = delta2_identifier; - DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node); - DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node); - TREE_UNSIGNED (fields[3]) = 0; - TREE_CHAIN (fields[2]) = fields[3]; - vtable_entry_type = build_qualified_type (vtable_entry_type, - TYPE_QUAL_CONST); - } + { + /* Make sure we get a unique function type, so we can give + its pointer type a name. (This wins for gdb.) */ + tree vfunc_type = make_node (FUNCTION_TYPE); + TREE_TYPE (vfunc_type) = integer_type_node; + TYPE_ARG_TYPES (vfunc_type) = NULL_TREE; + layout_type (vfunc_type); + + vtable_entry_type = build_pointer_type (vfunc_type); + } record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type); vtbl_type_node = build_cplus_array_type (vtable_entry_type, NULL_TREE); layout_type (vtbl_type_node); vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST); - record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node); + record_builtin_type (RID_MAX, NULL, vtbl_type_node); vtbl_ptr_type_node = build_pointer_type (vtable_entry_type); layout_type (vtbl_ptr_type_node); - record_builtin_type (RID_MAX, NULL_PTR, vtbl_ptr_type_node); - - if (flag_vtable_thunks) - { - /* We need vlists only when using thunks; otherwise leave them - as NULL_TREE. That way, it doesn't get into the way of the - mangling. */ - vlist_type_node = build_pointer_type (vtbl_ptr_type_node); - vlist_zero_node = build_int_2 (0, 0); - TREE_TYPE (vlist_zero_node) = vlist_type_node; - } - - /* Simplify life by making a "sigtable_entry_type". Give its - fields names so that the debugger can use them. */ - - if (flag_handle_signatures) - { - sigtable_entry_type = make_lang_type (RECORD_TYPE); - fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier, - delta_type_node); - fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier, - delta_type_node); - fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier, - delta_type_node); - fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier, - delta_type_node); - fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier, - ptr_type_node); - - /* Set the alignment to the max of the alignment of ptr_type_node and - delta_type_node. Double alignment wastes a word on the Sparc. */ - finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4, - (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node)) - ? ptr_type_node - : delta_type_node); - - /* Make this part of an invisible union. */ - fields[5] = copy_node (fields[4]); - TREE_TYPE (fields[5]) = delta_type_node; - DECL_NAME (fields[5]) = vt_off_identifier; - DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node); - DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node); - TREE_UNSIGNED (fields[5]) = 0; - TREE_CHAIN (fields[4]) = fields[5]; - - sigtable_entry_type = build_qualified_type (sigtable_entry_type, - TYPE_QUAL_CONST); - record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type); - } - - std_node = build_decl (NAMESPACE_DECL, - get_identifier (flag_honor_std ? "fake std":"std"), - void_type_node); - pushdecl (std_node); + record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node); + + push_namespace (get_identifier ("__cxxabiv1")); + abi_node = current_namespace; + pop_namespace (); global_type_node = make_node (LANG_TYPE); record_unknown_type (global_type_node, "global type"); @@ -6925,111 +6567,335 @@ init_decl_processing () { tree bad_alloc_type_node, newtype, deltype; - if (flag_honor_std) - push_namespace (get_identifier ("std")); + tree ptr_ftype_sizetype; + + push_namespace (std_identifier); bad_alloc_type_node = xref_tag (class_type_node, get_identifier ("bad_alloc"), 1); - if (flag_honor_std) - pop_namespace (); + pop_namespace (); + ptr_ftype_sizetype + = build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + c_size_type_node, + void_list_node)); newtype = build_exception_variant - (ptr_ftype_sizetype, build_tree_list (NULL_TREE, bad_alloc_type_node)); - deltype = build_exception_variant - (void_ftype_ptr, build_tree_list (NULL_TREE, NULL_TREE)); - auto_function (ansi_opname[(int) NEW_EXPR], newtype, NOT_BUILT_IN); - auto_function (ansi_opname[(int) VEC_NEW_EXPR], newtype, NOT_BUILT_IN); - global_delete_fndecl - = auto_function (ansi_opname[(int) DELETE_EXPR], deltype, NOT_BUILT_IN); - auto_function (ansi_opname[(int) VEC_DELETE_EXPR], deltype, NOT_BUILT_IN); + (ptr_ftype_sizetype, add_exception_specifier + (NULL_TREE, bad_alloc_type_node, -1)); + deltype = build_exception_variant (void_ftype_ptr, empty_except_spec); + push_cp_library_fn (NEW_EXPR, newtype); + push_cp_library_fn (VEC_NEW_EXPR, newtype); + global_delete_fndecl = push_cp_library_fn (DELETE_EXPR, deltype); + push_cp_library_fn (VEC_DELETE_EXPR, deltype); } abort_fndecl - = define_function ("__pure_virtual", void_ftype, - NOT_BUILT_IN, 0, 0); + = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype); /* Perform other language dependent initializations. */ init_class_processing (); init_init_processing (); init_search_processing (); - if (flag_rtti) - init_rtti_processing (); + init_rtti_processing (); if (flag_exceptions) init_exception_processing (); - if (flag_no_inline) - { - flag_inline_functions = 0; - } if (! supports_one_only ()) flag_weak = 0; - /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ - declare_function_name (); - - /* Prepare to check format strings against argument lists. */ - init_function_format_info (); + make_fname_decl = cp_make_fname_decl; + start_fname_decls (); /* Show we use EH for cleanups. */ using_eh_for_cleanups (); - print_error_function = lang_print_error_function; - lang_get_alias_set = &c_get_alias_set; - valid_lang_attribute = cp_valid_lang_attribute; - /* Maintain consistency. Perhaps we should just complain if they say -fwritable-strings? */ if (flag_writable_strings) flag_const_strings = 0; + + /* Add GC roots for all of our global variables. */ + ggc_add_tree_root (c_global_trees, sizeof c_global_trees / sizeof(tree)); + ggc_add_tree_root (cp_global_trees, sizeof cp_global_trees / sizeof(tree)); + ggc_add_tree_root (&integer_three_node, 1); + ggc_add_tree_root (&integer_two_node, 1); + ggc_add_tree_root (&signed_size_zero_node, 1); + ggc_add_tree_root (&size_one_node, 1); + ggc_add_tree_root (&size_zero_node, 1); + ggc_add_root (&global_binding_level, 1, sizeof global_binding_level, + mark_binding_level); + ggc_add_root (&scope_chain, 1, sizeof scope_chain, &mark_saved_scope); + ggc_add_tree_root (&static_ctors, 1); + ggc_add_tree_root (&static_dtors, 1); + ggc_add_tree_root (&lastiddecl, 1); + + ggc_add_tree_root (&last_function_parms, 1); + ggc_add_tree_root (&error_mark_list, 1); + + ggc_add_tree_root (&global_namespace, 1); + ggc_add_tree_root (&global_type_node, 1); + ggc_add_tree_root (&anonymous_namespace_name, 1); + + ggc_add_tree_root (&got_object, 1); + ggc_add_tree_root (&got_scope, 1); + + ggc_add_tree_root (¤t_lang_name, 1); + ggc_add_tree_root (&static_aggregates, 1); + ggc_add_tree_root (&free_bindings, 1); } -/* Function to print any language-specific context for an error message. */ +/* Generate an initializer for a function naming variable from + NAME. NAME may be NULL, in which case we generate a special + ERROR_MARK node which should be replaced later. */ -static void -lang_print_error_function (file) - char *file; +tree +cp_fname_init (name) + const char *name; +{ + tree domain = NULL_TREE; + tree type; + tree init = NULL_TREE; + size_t length = 0; + + if (name) + { + length = strlen (name); + domain = build_index_type (size_int (length)); + init = build_string (length + 1, name); + } + + type = build_qualified_type (char_type_node, TYPE_QUAL_CONST); + type = build_cplus_array_type (type, domain); + + if (init) + TREE_TYPE (init) = type; + else + /* We don't know the value until instantiation time. Make + something which will be digested now, but replaced later. */ + init = build (ERROR_MARK, type); + + return init; +} + +/* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the + decl, NAME is the initialization string and TYPE_DEP indicates whether + NAME depended on the type of the function. We make use of that to detect + __PRETTY_FUNCTION__ inside a template fn. This is being done + lazily at the point of first use, so we musn't push the decl now. */ + +static tree +cp_make_fname_decl (id, type_dep) + tree id; + int type_dep; { - default_print_error_function (file); - maybe_print_template_context (); + const char *const name = (type_dep && processing_template_decl + ? NULL : fname_as_string (type_dep)); + tree init = cp_fname_init (name); + tree decl = build_decl (VAR_DECL, id, TREE_TYPE (init)); + + /* As we don't push the decl here, we must set the context. */ + DECL_CONTEXT (decl) = current_function_decl; + DECL_PRETTY_FUNCTION_P (decl) = type_dep; + + TREE_STATIC (decl) = 1; + TREE_READONLY (decl) = 1; + DECL_ARTIFICIAL (decl) = 1; + DECL_INITIAL (decl) = init; + + TREE_USED (decl) = 1; + + cp_finish_decl (decl, init, NULL_TREE, LOOKUP_ONLYCONVERTING); + + return decl; } -/* Make a definition for a builtin function named NAME and whose data type +/* Entry point for the benefit of c_common_nodes_and_builtins. + + Make a definition for a builtin function named NAME and whose data type is TYPE. TYPE should be a function type with argument types. - FUNCTION_CODE tells later passes how to compile calls to this function. - See tree.h for its possible values. - If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, + CLASS and CODE tell later passes how to compile calls to this function. + See tree.h for possible values. + + If LIBNAME is nonzero, use that for DECL_ASSEMBLER_NAME, the name to be called if we can't opencode the function. */ tree -define_function (name, type, function_code, pfn, library_name) +builtin_function (name, type, code, class, libname) const char *name; tree type; - enum built_in_function function_code; - void (*pfn) PROTO((tree)); - const char *library_name; + int code; + enum built_in_class class; + const char *libname; { - tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); - DECL_EXTERNAL (decl) = 1; - TREE_PUBLIC (decl) = 1; - DECL_ARTIFICIAL (decl) = 1; + tree decl = build_library_fn_1 (get_identifier (name), ERROR_MARK, type); + DECL_BUILT_IN_CLASS (decl) = class; + DECL_FUNCTION_CODE (decl) = code; my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 392); - DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); + + /* All builtins that don't begin with an `_' should go in the `std' + namespace. */ + if (name[0] != '_') + { + push_namespace (std_identifier); + DECL_CONTEXT (decl) = std_node; + } + pushdecl (decl); + if (name[0] != '_') + pop_namespace (); /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, we cannot change DECL_ASSEMBLER_NAME until we have installed this function in the namespace. */ - if (pfn) (*pfn) (decl); - if (library_name) - DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); - make_function_rtl (decl); - if (function_code != NOT_BUILT_IN) - { - DECL_BUILT_IN (decl) = 1; - DECL_FUNCTION_CODE (decl) = function_code; - } + if (libname) + SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname)); + make_decl_rtl (decl, NULL); + + /* Warn if a function in the namespace for users + is used without an occasion to consider it declared. */ + if (name[0] != '_' || name[1] != '_') + DECL_ANTICIPATED (decl) = 1; + + /* Possibly apply some default attributes to this built-in function. */ + decl_attributes (&decl, NULL_TREE, 0); + return decl; } + +/* Generate a FUNCTION_DECL with the typical flags for a runtime library + function. Not called directly. */ + +static tree +build_library_fn_1 (name, operator_code, type) + tree name; + enum tree_code operator_code; + tree type; +{ + tree fn = build_lang_decl (FUNCTION_DECL, name, type); + DECL_EXTERNAL (fn) = 1; + TREE_PUBLIC (fn) = 1; + DECL_ARTIFICIAL (fn) = 1; + TREE_NOTHROW (fn) = 1; + SET_OVERLOADED_OPERATOR_CODE (fn, operator_code); + SET_DECL_LANGUAGE (fn, lang_c); + return fn; +} + +/* Returns the _DECL for a library function with C linkage. + We assume that such functions never throw; if this is incorrect, + callers should unset TREE_NOTHROW. */ + +tree +build_library_fn (name, type) + tree name; + tree type; +{ + return build_library_fn_1 (name, ERROR_MARK, type); +} + +/* Returns the _DECL for a library function with C++ linkage. */ + +static tree +build_cp_library_fn (name, operator_code, type) + tree name; + enum tree_code operator_code; + tree type; +{ + tree fn = build_library_fn_1 (name, operator_code, type); + TREE_NOTHROW (fn) = TYPE_NOTHROW_P (type); + DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace); + SET_DECL_LANGUAGE (fn, lang_cplusplus); + set_mangled_name_for_decl (fn); + return fn; +} + +/* Like build_library_fn, but takes a C string instead of an + IDENTIFIER_NODE. */ + +tree +build_library_fn_ptr (name, type) + const char *name; + tree type; +{ + return build_library_fn (get_identifier (name), type); +} + +/* Like build_cp_library_fn, but takes a C string instead of an + IDENTIFIER_NODE. */ + +tree +build_cp_library_fn_ptr (name, type) + const char *name; + tree type; +{ + return build_cp_library_fn (get_identifier (name), ERROR_MARK, type); +} + +/* Like build_library_fn, but also pushes the function so that we will + be able to find it via IDENTIFIER_GLOBAL_VALUE. */ + +tree +push_library_fn (name, type) + tree name, type; +{ + tree fn = build_library_fn (name, type); + pushdecl_top_level (fn); + return fn; +} + +/* Like build_cp_library_fn, but also pushes the function so that it + will be found by normal lookup. */ + +static tree +push_cp_library_fn (operator_code, type) + enum tree_code operator_code; + tree type; +{ + tree fn = build_cp_library_fn (ansi_opname (operator_code), + operator_code, + type); + pushdecl (fn); + return fn; +} + +/* Like push_library_fn, but takes a TREE_LIST of parm types rather than + a FUNCTION_TYPE. */ + +tree +push_void_library_fn (name, parmtypes) + tree name, parmtypes; +{ + tree type = build_function_type (void_type_node, parmtypes); + return push_library_fn (name, type); +} + +/* Like push_library_fn, but also note that this function throws + and does not return. Used for __throw_foo and the like. */ + +tree +push_throw_library_fn (name, type) + tree name, type; +{ + tree fn = push_library_fn (name, type); + TREE_THIS_VOLATILE (fn) = 1; + TREE_NOTHROW (fn) = 0; + return fn; +} + +/* Apply default attributes to a function, if a system function with default + attributes. */ + +void +insert_default_attributes (decl) + tree decl; +{ + if (!DECL_EXTERN_C_FUNCTION_P (decl)) + return; + if (!TREE_PUBLIC (decl)) + return; + c_common_insert_default_attributes (decl); +} /* When we call finish_struct for an anonymous union, we create default copy constructors and such. But, an anonymous union @@ -7042,7 +6908,7 @@ define_function (name, type, function_code, pfn, library_name) union type.) */ void -fixup_anonymous_union (t) +fixup_anonymous_aggr (t) tree t; { tree *q; @@ -7066,10 +6932,36 @@ fixup_anonymous_union (t) q = &TREE_CHAIN (*q); } - /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have - function members. */ + /* ISO C++ 9.5.3. Anonymous unions may not have function members. */ if (TYPE_METHODS (t)) - error ("an anonymous union cannot have function members"); + cp_error_at ("an anonymous union cannot have function members", t); + + /* Anonymous aggregates cannot have fields with ctors, dtors or complex + assignment operators (because they cannot have these methods themselves). + For anonymous unions this is already checked because they are not allowed + in any union, otherwise we have to check it. */ + if (TREE_CODE (t) != UNION_TYPE) + { + tree field, type; + + for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field)) + if (TREE_CODE (field) == FIELD_DECL) + { + type = TREE_TYPE (field); + if (CLASS_TYPE_P (type)) + { + if (TYPE_NEEDS_CONSTRUCTING (type)) + cp_error_at ("member %#D' with constructor not allowed in anonymous aggregate", + field); + if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) + cp_error_at ("member %#D' with destructor not allowed in anonymous aggregate", + field); + if (TYPE_HAS_COMPLEX_ASSIGN_REF (type)) + cp_error_at ("member %#D' with copy assignment operator not allowed in anonymous aggregate", + field); + } + } + } } /* Make sure that a declaration with no declarator is well-formed, i.e. @@ -7082,6 +6974,8 @@ check_tag_decl (declspecs) tree declspecs; { int found_type = 0; + int saw_friend = 0; + int saw_typedef = 0; tree ob_modifier = NULL_TREE; register tree link; register tree t = NULL_TREE; @@ -7090,21 +6984,38 @@ check_tag_decl (declspecs) { register tree value = TREE_VALUE (link); - if (TYPE_P (value)) + if (TYPE_P (value) + || TREE_CODE (value) == TYPE_DECL + || (TREE_CODE (value) == IDENTIFIER_NODE + && IDENTIFIER_GLOBAL_VALUE (value) + && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (value)) == TYPE_DECL)) { ++found_type; - if (IS_AGGR_TYPE (value) || TREE_CODE (value) == ENUMERAL_TYPE) + if (found_type == 2 && TREE_CODE (value) == IDENTIFIER_NODE) + { + if (! in_system_header) + pedwarn ("redeclaration of C++ built-in type `%T'", value); + return NULL_TREE; + } + + if (TYPE_P (value) + && ((TREE_CODE (value) != TYPENAME_TYPE && IS_AGGR_TYPE (value)) + || TREE_CODE (value) == ENUMERAL_TYPE)) { my_friendly_assert (TYPE_MAIN_DECL (value) != NULL_TREE, 261); t = value; } } + else if (value == ridpointers[(int) RID_TYPEDEF]) + saw_typedef = 1; else if (value == ridpointers[(int) RID_FRIEND]) { if (current_class_type == NULL_TREE || current_scope () != current_class_type) ob_modifier = value; + else + saw_friend = 1; } else if (value == ridpointers[(int) RID_STATIC] || value == ridpointers[(int) RID_EXTERN] @@ -7121,34 +7032,53 @@ check_tag_decl (declspecs) if (found_type > 1) error ("multiple types in one declaration"); - /* Inside a class, we might be in a friend or access declaration. - Until we have a good way of detecting the latter, don't warn. */ - if (t == NULL_TREE && ! current_class_type) + if (t == NULL_TREE && ! saw_friend) pedwarn ("declaration does not declare anything"); - /* Check for an anonymous union. We're careful - accessing TYPE_IDENTIFIER because some built-in types, like - pointer-to-member types, do not have TYPE_NAME. */ - else if (t && TREE_CODE (t) == UNION_TYPE - && TYPE_NAME (t) - && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) - { + /* Check for an anonymous union. */ + else if (t && IS_AGGR_TYPE_CODE (TREE_CODE (t)) + && TYPE_ANONYMOUS_P (t)) + { + /* 7/3 In a simple-declaration, the optional init-declarator-list + can be omitted only when declaring a class (clause 9) or + enumeration (7.2), that is, when the decl-specifier-seq contains + either a class-specifier, an elaborated-type-specifier with + a class-key (9.1), or an enum-specifier. In these cases and + whenever a class-specifier or enum-specifier is present in the + decl-specifier-seq, the identifiers in these specifiers are among + the names being declared by the declaration (as class-name, + enum-names, or enumerators, depending on the syntax). In such + cases, and except for the declaration of an unnamed bit-field (9.6), + the decl-specifier-seq shall introduce one or more names into the + program, or shall redeclare a name introduced by a previous + declaration. [Example: + enum { }; // ill-formed + typedef class { }; // ill-formed + --end example] */ + if (saw_typedef) + { + error ("missing type-name in typedef-declaration"); + return NULL_TREE; + } /* Anonymous unions are objects, so they can have specifiers. */; - SET_ANON_UNION_TYPE_P (t); + SET_ANON_AGGR_TYPE_P (t); + + if (TREE_CODE (t) != UNION_TYPE && pedantic && ! in_system_header) + pedwarn ("ISO C++ prohibits anonymous structs"); } else if (ob_modifier) { if (ob_modifier == ridpointers[(int) RID_INLINE] || ob_modifier == ridpointers[(int) RID_VIRTUAL]) - cp_error ("`%D' can only be specified for functions", ob_modifier); + error ("`%D' can only be specified for functions", ob_modifier); else if (ob_modifier == ridpointers[(int) RID_FRIEND]) - cp_error ("`%D' can only be specified inside a class", ob_modifier); + error ("`%D' can only be specified inside a class", ob_modifier); else if (ob_modifier == ridpointers[(int) RID_EXPLICIT]) - cp_error ("`%D' can only be specified for constructors", + error ("`%D' can only be specified for constructors", ob_modifier); else - cp_error ("`%D' can only be specified for objects and functions", + error ("`%D' can only be specified for objects and functions", ob_modifier); } @@ -7180,14 +7110,14 @@ shadow_tag (declspecs) union { ... } ; because there is no declarator after the union, the parser sends that declaration here. */ - if (t && ANON_UNION_TYPE_P (t)) + if (t && ANON_AGGR_TYPE_P (t)) { - fixup_anonymous_union (t); + fixup_anonymous_aggr (t); if (TYPE_FIELDS (t)) { tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, - NULL_TREE); + NULL); finish_anon_union (decl); } } @@ -7199,11 +7129,16 @@ tree groktypename (typename) tree typename; { + tree specs, attrs; + tree type; if (TREE_CODE (typename) != TREE_LIST) return typename; - return grokdeclarator (TREE_VALUE (typename), - TREE_PURPOSE (typename), - TYPENAME, 0, NULL_TREE); + split_specs_attrs (TREE_PURPOSE (typename), &specs, &attrs); + type = grokdeclarator (TREE_VALUE (typename), specs, + TYPENAME, 0, &attrs); + if (attrs) + cplus_decl_attributes (&type, attrs, 0); + return type; } /* Decode a declarator in an ordinary declaration or data definition. @@ -7221,22 +7156,17 @@ groktypename (typename) do go through here. Structure field declarations are done by grokfield and not through here. */ -/* Set this to zero to debug not using the temporary obstack - to parse initializers. */ -int debug_temp_inits = 1; - tree start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) tree declarator, declspecs; int initialized; tree attributes, prefix_attributes; { - register tree decl; + tree decl; register tree type, tem; tree context; extern int have_extern_spec; extern int used_extern_spec; - tree attrlist; #if 0 /* See code below that used this. */ @@ -7246,19 +7176,23 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) /* This should only be done once on the top most decl. */ if (have_extern_spec && !used_extern_spec) { - declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), - declspecs); + declspecs = tree_cons (NULL_TREE, get_identifier ("extern"), + declspecs); used_extern_spec = 1; } - if (attributes || prefix_attributes) - attrlist = build_scratch_list (attributes, prefix_attributes); - else - attrlist = NULL_TREE; + /* An object declared as __attribute__((deprecated)) suppresses + warnings of uses of other deprecated items. */ + if (lookup_attribute ("deprecated", attributes)) + deprecated_state = DEPRECATED_SUPPRESS; + + attributes = chainon (attributes, prefix_attributes); decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, - attrlist); - + &attributes); + + deprecated_state = DEPRECATED_NORMAL; + if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE) return NULL_TREE; @@ -7267,30 +7201,7 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) if (type == error_mark_node) return NULL_TREE; - /* Don't lose if destructors must be executed at file-level. */ - if (! processing_template_decl && TREE_STATIC (decl) - && TYPE_NEEDS_DESTRUCTOR (complete_type (type)) - && !TREE_PERMANENT (decl)) - { - push_obstacks (&permanent_obstack, &permanent_obstack); - decl = copy_node (decl); - if (TREE_CODE (type) == ARRAY_TYPE) - { - tree itype = TYPE_DOMAIN (type); - if (itype && ! TREE_PERMANENT (itype)) - { - itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype))); - type = build_cplus_array_type (TREE_TYPE (type), itype); - TREE_TYPE (decl) = type; - } - } - pop_obstacks (); - } - - context - = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) - ? DECL_CLASS_CONTEXT (decl) - : DECL_CONTEXT (decl); + context = DECL_CONTEXT (decl); if (initialized && context && TREE_CODE (context) == NAMESPACE_DECL && context != current_namespace && TREE_CODE (decl) == VAR_DECL) @@ -7316,46 +7227,25 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) Any other case of an initialization in a TYPE_DECL is an error. */ if (pedantic || list_length (declspecs) > 1) { - cp_error ("typedef `%D' is initialized", decl); + error ("typedef `%D' is initialized", decl); initialized = 0; } break; case FUNCTION_DECL: - cp_error ("function `%#D' is initialized like a variable", decl); + error ("function `%#D' is initialized like a variable", decl); initialized = 0; break; default: - if (! processing_template_decl) - { - if (type != error_mark_node) - { - if (TYPE_SIZE (type) != NULL_TREE - && ! TREE_CONSTANT (TYPE_SIZE (type))) - { - cp_error - ("variable-sized object `%D' may not be initialized", - decl); - initialized = 0; - } - - if (TREE_CODE (type) == ARRAY_TYPE - && TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) - { - cp_error - ("elements of array `%#D' have incomplete type", decl); - initialized = 0; - } - } - } + break; } if (initialized) { if (! toplevel_bindings_p () && DECL_EXTERNAL (decl)) - cp_warning ("declaration of `%#D' has `extern' and is initialized", + warning ("declaration of `%#D' has `extern' and is initialized", decl); DECL_EXTERNAL (decl) = 0; if (toplevel_bindings_p ()) @@ -7367,14 +7257,17 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) DECL_INITIAL (decl) = error_mark_node; } -#ifdef SET_DEFAULT_DECL_ATTRIBUTES - SET_DEFAULT_DECL_ATTRIBUTES (decl, attributes); -#endif - /* Set attributes here so if duplicate decl, will have proper attributes. */ - cplus_decl_attributes (decl, attributes, prefix_attributes); + cplus_decl_attributes (&decl, attributes, 0); - if (context && TYPE_SIZE (complete_type (context)) != NULL_TREE) + if (TREE_CODE (decl) == FUNCTION_DECL + && DECL_DECLARED_INLINE_P (decl) + && DECL_UNINLINABLE (decl) + && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl))) + warning_with_decl (decl, + "inline function `%s' given attribute noinline"); + + if (context && COMPLETE_TYPE_P (complete_type (context))) { push_nested_class (context, 2); @@ -7382,12 +7275,12 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) { tree field = lookup_field (context, DECL_NAME (decl), 0, 0); if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) - cp_error ("`%#D' is not a static member of `%#T'", decl, context); + error ("`%#D' is not a static member of `%#T'", decl, context); else { if (DECL_CONTEXT (field) != context) { - cp_pedwarn ("ANSI C++ does not permit `%T::%D' to be defined as `%T::%D'", + pedwarn ("ISO C++ does not permit `%T::%D' to be defined as `%T::%D'", DECL_CONTEXT (field), DECL_NAME (decl), context, DECL_NAME (decl)); DECL_CONTEXT (decl) = DECL_CONTEXT (field); @@ -7398,7 +7291,7 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) initialization. Thus, duplicate_decls won't warn about this situation, and so we check here. */ if (DECL_INITIAL (decl) && DECL_INITIAL (field)) - cp_error ("duplicate initialization of %D", decl); + error ("duplicate initialization of %D", decl); if (duplicate_decls (decl, field)) decl = field; } @@ -7412,8 +7305,8 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */ DECL_IN_AGGR_P (decl) = 0; - if ((DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl)) - || CLASSTYPE_USE_TEMPLATE (context)) + if ((DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl)) + || CLASSTYPE_TEMPLATE_INSTANTIATION (context)) { SET_DECL_TEMPLATE_SPECIALIZATION (decl); /* [temp.expl.spec] An explicit specialization of a static data @@ -7427,40 +7320,15 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) } if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)) - cp_pedwarn ("declaration of `%#D' outside of class is not definition", + pedwarn ("declaration of `%#D' outside of class is not definition", decl); } - /* Add this decl to the current binding level, but not if it - comes from another scope, e.g. a static member variable. - TEM may equal DECL or it may be a previous decl of the same name. */ - - if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE - /* Definitions of namespace members outside their namespace are - possible. */ - && TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL) - || (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ()) - || TREE_CODE (type) == LANG_TYPE - /* The declaration of template specializations does not affect - the functions available for overload resolution, so we do not - call pushdecl. */ - || (TREE_CODE (decl) == FUNCTION_DECL - && DECL_TEMPLATE_SPECIALIZATION (decl))) - tem = decl; - else - tem = pushdecl (decl); + /* Enter this declaration into the symbol table. */ + tem = maybe_push_decl (decl); if (processing_template_decl) - { - if (! current_function_decl) - tem = push_template_decl (tem); - else if (minimal_parse_mode) - DECL_VINDEX (tem) - = build_min_nt (DECL_STMT, copy_to_permanent (declarator), - copy_to_permanent (declspecs), - NULL_TREE); - } - + tem = push_template_decl (tem); #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) /* Tell the back-end to use or not use .common as appropriate. If we say @@ -7470,39 +7338,10 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) data segment. */ DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem); #endif - + if (! processing_template_decl) start_decl_1 (tem); - /* Corresponding pop_obstacks is done in `cp_finish_decl'. */ - push_obstacks_nochange (); - -#if 0 - /* We have no way of knowing whether the initializer will need to be - evaluated at run-time or not until we've parsed it, so let's just put - it in the permanent obstack. (jason) */ - if (init_written - && ! (TREE_CODE (tem) == PARM_DECL - || (TREE_READONLY (tem) - && (TREE_CODE (tem) == VAR_DECL - || TREE_CODE (tem) == FIELD_DECL)))) - { - /* When parsing and digesting the initializer, - use temporary storage. Do this even if we will ignore the value. */ - if (toplevel_bindings_p () && debug_temp_inits) - { - if (processing_template_decl - || TYPE_NEEDS_CONSTRUCTING (type) - || TREE_CODE (type) == REFERENCE_TYPE) - /* In this case, the initializer must lay down in permanent - storage, since it will be saved until `finish_file' is run. */ - ; - else - temporary_allocation (); - } - } -#endif - return tem; } @@ -7516,12 +7355,7 @@ start_decl_1 (decl) if (type == error_mark_node) return; - /* If this type of object needs a cleanup, and control may - jump past it, make a new binding level so that it is cleaned - up only when it is initialized first. */ - if (TYPE_NEEDS_DESTRUCTOR (type) - && current_binding_level->more_cleanups_ok == 0) - pushlevel_temporary (1); + maybe_push_cleanup_level (type); if (initialized) /* Is it valid for this decl to have an initializer at all? @@ -7530,19 +7364,19 @@ start_decl_1 (decl) { /* Don't allow initializations for incomplete types except for arrays which might be completed by the initialization. */ - if (TYPE_SIZE (complete_type (type)) != NULL_TREE) + if (COMPLETE_TYPE_P (complete_type (type))) ; /* A complete type is ok. */ else if (TREE_CODE (type) != ARRAY_TYPE) { - cp_error ("variable `%#D' has initializer but incomplete type", + error ("variable `%#D' has initializer but incomplete type", decl); initialized = 0; type = TREE_TYPE (decl) = error_mark_node; } - else if (TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) + else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type)))) { if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)) - cp_error ("elements of array `%#D' have incomplete type", decl); + error ("elements of array `%#D' have incomplete type", decl); /* else we already gave an error in start_decl. */ initialized = 0; } @@ -7551,12 +7385,14 @@ start_decl_1 (decl) if (!initialized && TREE_CODE (decl) != TYPE_DECL && TREE_CODE (decl) != TEMPLATE_DECL - && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) + && type != error_mark_node + && IS_AGGR_TYPE (type) + && ! DECL_EXTERNAL (decl)) { if ((! processing_template_decl || ! uses_template_parms (type)) - && TYPE_SIZE (complete_type (type)) == NULL_TREE) + && !COMPLETE_TYPE_P (complete_type (type))) { - cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", + error ("aggregate `%#D' has incomplete type and cannot be initialized", decl); /* Change the type so that assemble_variable will give DECL an rtl we can live with: (mem (const_int 0)). */ @@ -7574,23 +7410,6 @@ start_decl_1 (decl) } } -#if 0 - /* We don't do this yet for GNU C++. */ - /* For a local variable, define the RTL now. */ - if (! toplevel_bindings_p () - /* But not if this is a duplicate decl - and we preserved the rtl from the previous one - (which may or may not happen). */ - && DECL_RTL (tem) == NULL_RTX) - { - if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) - expand_decl (tem); - else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE - && DECL_INITIAL (tem) != NULL_TREE) - expand_decl (tem); - } -#endif - if (! initialized) DECL_INITIAL (decl) = NULL_TREE; } @@ -7601,7 +7420,7 @@ start_decl_1 (decl) Quotes on semantics can be found in ARM 8.4.3. */ -static void +static tree grok_reference_init (decl, type, init) tree decl, type, init; { @@ -7612,22 +7431,17 @@ grok_reference_init (decl, type, init) if ((DECL_LANG_SPECIFIC (decl) == 0 || DECL_IN_AGGR_P (decl) == 0) && ! DECL_THIS_EXTERN (decl)) - { - cp_error ("`%D' declared as reference but not initialized", decl); - if (TREE_CODE (decl) == VAR_DECL) - SET_DECL_REFERENCE_SLOT (decl, error_mark_node); - } - return; + error ("`%D' declared as reference but not initialized", decl); + return NULL_TREE; } if (init == error_mark_node) - return; + return NULL_TREE; - if (TREE_CODE (type) == REFERENCE_TYPE - && TREE_CODE (init) == CONSTRUCTOR) + if (TREE_CODE (init) == CONSTRUCTOR) { - cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl); - return; + error ("ISO C++ forbids use of initializer list to initialize reference `%D'", decl); + return NULL_TREE; } if (TREE_CODE (init) == TREE_LIST) @@ -7643,44 +7457,32 @@ grok_reference_init (decl, type, init) init = default_conversion (init); } + /* Convert INIT to the reference type TYPE. This may involve the + creation of a temporary, whose lifetime must be the same as that + of the reference. If so, a DECL_STMT for the temporary will be + added just after the DECL_STMT for DECL. That's why we don't set + DECL_INITIAL for local references (instead assigning to them + explicitly); we need to allow the temporary to be initialized + first. */ tmp = convert_to_reference (type, init, CONV_IMPLICIT, - LOOKUP_SPECULATIVELY|LOOKUP_NORMAL|DIRECT_BIND, decl); + LOOKUP_ONLYCONVERTING|LOOKUP_SPECULATIVELY|LOOKUP_NORMAL|DIRECT_BIND, + decl); if (tmp == error_mark_node) - goto fail; - else if (tmp != NULL_TREE) - { - init = tmp; - DECL_INITIAL (decl) = save_expr (init); - } - else + return NULL_TREE; + else if (tmp == NULL_TREE) { - cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init)); - goto fail; + error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init)); + return NULL_TREE; } - /* ?? Can this be optimized in some cases to - hand back the DECL_INITIAL slot?? */ - if (TYPE_SIZE (TREE_TYPE (type))) - { - init = convert_from_reference (decl); - if (TREE_PERMANENT (decl)) - init = copy_to_permanent (init); - SET_DECL_REFERENCE_SLOT (decl, init); - } + if (TREE_STATIC (decl) && !TREE_CONSTANT (tmp)) + return tmp; - if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl))) - { - expand_static_init (decl, DECL_INITIAL (decl)); - DECL_INITIAL (decl) = NULL_TREE; - } - return; + DECL_INITIAL (decl) = tmp; - fail: - if (TREE_CODE (decl) == VAR_DECL) - SET_DECL_REFERENCE_SLOT (decl, error_mark_node); - return; + return NULL_TREE; } /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from @@ -7710,6 +7512,164 @@ obscure_complex_init (decl, init) return init; } +/* When parsing `int a[] = {1, 2};' we don't know the size of the + array until we finish parsing the initializer. If that's the + situation we're in, update DECL accordingly. */ + +static void +maybe_deduce_size_from_array_init (decl, init) + tree decl; + tree init; +{ + tree type = TREE_TYPE (decl); + + if (TREE_CODE (type) == ARRAY_TYPE + && TYPE_DOMAIN (type) == NULL_TREE + && TREE_CODE (decl) != TYPE_DECL) + { + /* do_default is really a C-ism to deal with tentative definitions. + But let's leave it here to ease the eventual merge. */ + int do_default = !DECL_EXTERNAL (decl); + tree initializer = init ? init : DECL_INITIAL (decl); + int failure = complete_array_type (type, initializer, do_default); + + if (failure == 1) + error ("initializer fails to determine size of `%D'", decl); + + if (failure == 2) + { + if (do_default) + error ("array size missing in `%D'", decl); + /* If a `static' var's size isn't known, make it extern as + well as static, so it does not get allocated. If it's not + `static', then don't mark it extern; finish_incomplete_decl + will give it a default size and it will get allocated. */ + else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) + DECL_EXTERNAL (decl) = 1; + } + + if (pedantic && TYPE_DOMAIN (type) != NULL_TREE + && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), + integer_zero_node)) + error ("zero-size array `%D'", decl); + + layout_decl (decl, 0); + } +} + +/* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue + any appropriate error messages regarding the layout. */ + +static void +layout_var_decl (decl) + tree decl; +{ + tree type = TREE_TYPE (decl); +#if 0 + tree ttype = target_type (type); +#endif + + /* If we haven't already layed out this declaration, do so now. + Note that we must not call complete type for an external object + because it's type might involve templates that we are not + supposed to isntantiate yet. (And it's perfectly legal to say + `extern X x' for some incomplete type `X'.) */ + if (!DECL_EXTERNAL (decl)) + complete_type (type); + if (!DECL_SIZE (decl) && COMPLETE_TYPE_P (type)) + layout_decl (decl, 0); + + if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) + { + /* An automatic variable with an incomplete type: that is an error. + Don't talk about array types here, since we took care of that + message in grokdeclarator. */ + error ("storage size of `%D' isn't known", decl); + TREE_TYPE (decl) = error_mark_node; + } +#if 0 + /* Keep this code around in case we later want to control debug info + based on whether a type is "used". (jason 1999-11-11) */ + + else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) + /* Let debugger know it should output info for this type. */ + note_debug_info_needed (ttype); + + if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl)) + note_debug_info_needed (DECL_CONTEXT (decl)); +#endif + + if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) + && DECL_SIZE (decl) != NULL_TREE + && ! TREE_CONSTANT (DECL_SIZE (decl))) + { + if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) + constant_expression_warning (DECL_SIZE (decl)); + else + error ("storage size of `%D' isn't constant", decl); + } + + if (TREE_STATIC (decl) + && !DECL_ARTIFICIAL (decl) + && current_function_decl + && DECL_CONTEXT (decl) == current_function_decl) + push_local_name (decl); +} + +/* If a local static variable is declared in an inline function, or if + we have a weak definition, we must endeavor to create only one + instance of the variable at link-time. */ + +static void +maybe_commonize_var (decl) + tree decl; +{ + /* Static data in a function with comdat linkage also has comdat + linkage. */ + if (TREE_STATIC (decl) + /* Don't mess with __FUNCTION__. */ + && ! DECL_ARTIFICIAL (decl) + && current_function_decl + && DECL_CONTEXT (decl) == current_function_decl + && (DECL_DECLARED_INLINE_P (current_function_decl) + || DECL_TEMPLATE_INSTANTIATION (current_function_decl)) + && TREE_PUBLIC (current_function_decl)) + { + /* If flag_weak, we don't need to mess with this, as we can just + make the function weak, and let it refer to its unique local + copy. This works because we don't allow the function to be + inlined. */ + if (! flag_weak) + { + if (DECL_INTERFACE_KNOWN (current_function_decl)) + { + TREE_PUBLIC (decl) = 1; + DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl); + } + else if (DECL_INITIAL (decl) == NULL_TREE + || DECL_INITIAL (decl) == error_mark_node) + { + TREE_PUBLIC (decl) = 1; + DECL_COMMON (decl) = 1; + } + /* else we lose. We can only do this if we can use common, + which we can't if it has been initialized. */ + + if (!TREE_PUBLIC (decl)) + { + cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl); + cp_warning_at (" you can work around this by removing the initializer", decl); + } + } + else + comdat_linkage (decl); + } + else if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl)) + /* Set it up again; we might have set DECL_INITIAL since the last + time. */ + comdat_linkage (decl); +} + /* Issue an error message if DECL is an uninitialized const variable. */ static void @@ -7726,7 +7686,354 @@ check_for_uninitialized_const_var (decl) && CP_TYPE_CONST_P (type) && !TYPE_NEEDS_CONSTRUCTING (type) && !DECL_INITIAL (decl)) - cp_error ("uninitialized const `%D'", decl); + error ("uninitialized const `%D'", decl); +} + +/* Verify INIT (the initializer for DECL), and record the + initialization in DECL_INITIAL, if appropriate. Returns a new + value for INIT. */ + +static tree +check_initializer (decl, init) + tree decl; + tree init; +{ + tree type; + + if (TREE_CODE (decl) == FIELD_DECL) + return init; + + type = TREE_TYPE (decl); + + /* If `start_decl' didn't like having an initialization, ignore it now. */ + if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) + init = NULL_TREE; + + /* Check the initializer. */ + if (init) + { + /* Things that are going to be initialized need to have complete + type. */ + TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl)); + + if (type == error_mark_node) + /* We will have already complained. */ + init = NULL_TREE; + else if (COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type))) + { + error ("variable-sized object `%D' may not be initialized", decl); + init = NULL_TREE; + } + else if (TREE_CODE (type) == ARRAY_TYPE + && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (type)))) + { + error ("elements of array `%#D' have incomplete type", decl); + init = NULL_TREE; + } + else if (TREE_CODE (type) != ARRAY_TYPE && !COMPLETE_TYPE_P (type)) + { + error ("`%D' has incomplete type", decl); + TREE_TYPE (decl) = error_mark_node; + init = NULL_TREE; + } + } + + if (TREE_CODE (decl) == CONST_DECL) + { + my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); + + DECL_INITIAL (decl) = init; + + my_friendly_assert (init != NULL_TREE, 149); + init = NULL_TREE; + } + else if (!DECL_EXTERNAL (decl) && TREE_CODE (type) == REFERENCE_TYPE) + { + init = grok_reference_init (decl, type, init); + if (init) + init = obscure_complex_init (decl, init); + } + else if (init) + { + if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type)) + { + if (TREE_CODE (type) == ARRAY_TYPE) + init = digest_init (type, init, (tree *) 0); + else if (TREE_CODE (init) == CONSTRUCTOR + && TREE_HAS_CONSTRUCTOR (init)) + { + if (TYPE_NON_AGGREGATE_CLASS (type)) + { + error ("`%D' must be initialized by constructor, not by `{...}'", + decl); + init = error_mark_node; + } + else + goto dont_use_constructor; + } + } + else + { + dont_use_constructor: + if (TREE_CODE (init) != TREE_VEC) + init = store_init_value (decl, init); + } + + if (init) + /* We must hide the initializer so that expand_decl + won't try to do something it does not understand. */ + init = obscure_complex_init (decl, init); + } + else if (DECL_EXTERNAL (decl)) + ; + else if (TYPE_P (type) + && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))) + { + tree core_type = strip_array_types (type); + + if (! TYPE_NEEDS_CONSTRUCTING (core_type)) + { + if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)) + error ("structure `%D' with uninitialized const members", decl); + if (CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)) + error ("structure `%D' with uninitialized reference members", + decl); + } + + check_for_uninitialized_const_var (decl); + + if (COMPLETE_TYPE_P (type) && TYPE_NEEDS_CONSTRUCTING (type)) + init = obscure_complex_init (decl, NULL_TREE); + + } + else + check_for_uninitialized_const_var (decl); + + return init; +} + +/* If DECL is not a local variable, give it RTL. */ + +static void +make_rtl_for_nonlocal_decl (decl, init, asmspec) + tree decl; + tree init; + const char *asmspec; +{ + int toplev = toplevel_bindings_p (); + int defer_p; + + /* Handle non-variables up front. */ + if (TREE_CODE (decl) != VAR_DECL) + { + rest_of_decl_compilation (decl, asmspec, toplev, at_eof); + return; + } + + /* If we see a class member here, it should be a static data + member. */ + if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl)) + { + my_friendly_assert (TREE_STATIC (decl), 19990828); + /* An in-class declaration of a static data member should be + external; it is only a declaration, and not a definition. */ + if (init == NULL_TREE) + my_friendly_assert (DECL_EXTERNAL (decl), 20000723); + } + + /* Set the DECL_ASSEMBLER_NAME for the variable. */ + if (asmspec) + { + SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec)); + /* The `register' keyword, when used together with an + asm-specification, indicates that the variable should be + placed in a particular register. */ + if (DECL_REGISTER (decl)) + DECL_C_HARD_REGISTER (decl) = 1; + } + + /* We don't create any RTL for local variables. */ + if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl)) + return; + + /* We defer emission of local statics until the corresponding + DECL_STMT is expanded. */ + defer_p = DECL_FUNCTION_SCOPE_P (decl) || DECL_VIRTUAL_P (decl); + + /* We try to defer namespace-scope static constants so that they are + not emitted into the object file unnecessarily. */ + if (!DECL_VIRTUAL_P (decl) + && TREE_READONLY (decl) + && DECL_INITIAL (decl) != NULL_TREE + && DECL_INITIAL (decl) != error_mark_node + && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)) + && toplev + && !TREE_PUBLIC (decl)) + { + /* Fool with the linkage according to #pragma interface. */ + if (!interface_unknown) + { + TREE_PUBLIC (decl) = 1; + DECL_EXTERNAL (decl) = interface_only; + } + + defer_p = 1; + } + + /* If we're deferring the variable, we only need to make RTL if + there's an ASMSPEC. Otherwise, we'll lazily create it later when + we need it. (There's no way to lazily create RTL for things that + have assembly specs because the information about the specifier + isn't stored in the tree, yet) */ + if (defer_p && asmspec) + make_decl_rtl (decl, asmspec); + /* If we're not deferring, go ahead and assemble the variable. */ + else if (!defer_p) + rest_of_decl_compilation (decl, asmspec, toplev, at_eof); +} + +/* The old ARM scoping rules injected variables declared in the + initialization statement of a for-statement into the surrounding + scope. We support this usage, in order to be backward-compatible. + DECL is a just-declared VAR_DECL; if necessary inject its + declaration into the surrounding scope. */ + +void +maybe_inject_for_scope_var (decl) + tree decl; +{ + if (!DECL_NAME (decl)) + return; + + if (current_binding_level->is_for_scope) + { + struct binding_level *outer + = current_binding_level->level_chain; + + /* Check to see if the same name is already bound at the outer + level, either because it was directly declared, or because a + dead for-decl got preserved. In either case, the code would + not have been valid under the ARM scope rules, so clear + is_for_scope for the current_binding_level. + + Otherwise, we need to preserve the temp slot for decl to last + into the outer binding level. */ + + tree outer_binding + = TREE_CHAIN (IDENTIFIER_BINDING (DECL_NAME (decl))); + + if (outer_binding && BINDING_LEVEL (outer_binding) == outer + && (TREE_CODE (BINDING_VALUE (outer_binding)) + == VAR_DECL) + && DECL_DEAD_FOR_LOCAL (BINDING_VALUE (outer_binding))) + { + BINDING_VALUE (outer_binding) + = DECL_SHADOWED_FOR_VAR (BINDING_VALUE (outer_binding)); + current_binding_level->is_for_scope = 0; + } + else if (DECL_IN_MEMORY_P (decl)) + preserve_temp_slots (DECL_RTL (decl)); + } +} + +/* Generate code to initialize DECL (a local variable). */ + +void +initialize_local_var (decl, init, flags) + tree decl; + tree init; + int flags; +{ + tree type = TREE_TYPE (decl); + + /* If the type is bogus, don't bother initializing the variable. */ + if (type == error_mark_node) + return; + + if (DECL_SIZE (decl) == NULL_TREE && !TREE_STATIC (decl)) + { + /* If we used it already as memory, it must stay in memory. */ + DECL_INITIAL (decl) = NULL_TREE; + TREE_ADDRESSABLE (decl) = TREE_USED (decl); + } + + /* Local statics are handled differently from ordinary automatic + variables. */ + if (TREE_STATIC (decl)) + { + if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE + || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) + expand_static_init (decl, init); + return; + } + + if (DECL_SIZE (decl) && type != error_mark_node) + { + int already_used; + + /* Compute and store the initial value. */ + already_used = TREE_USED (decl) || TREE_USED (type); + + if (init || TYPE_NEEDS_CONSTRUCTING (type)) + { + int saved_stmts_are_full_exprs_p; + + my_friendly_assert (building_stmt_tree (), 20000906); + saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p (); + current_stmt_tree ()->stmts_are_full_exprs_p = 1; + finish_expr_stmt (build_aggr_init (decl, init, flags)); + current_stmt_tree ()->stmts_are_full_exprs_p = + saved_stmts_are_full_exprs_p; + } + + /* Set this to 0 so we can tell whether an aggregate which was + initialized was ever used. Don't do this if it has a + destructor, so we don't complain about the 'resource + allocation is initialization' idiom. Now set + attribute((unused)) on types so decls of that type will be + marked used. (see TREE_USED, above.) */ + if (TYPE_NEEDS_CONSTRUCTING (type) + && ! already_used + && TYPE_HAS_TRIVIAL_DESTRUCTOR (type) + && DECL_NAME (decl)) + TREE_USED (decl) = 0; + else if (already_used) + TREE_USED (decl) = 1; + } +} + +/* Generate code to destroy DECL (a local variable). */ + +static void +destroy_local_var (decl) + tree decl; +{ + tree type = TREE_TYPE (decl); + tree cleanup; + + /* Only variables get cleaned up. */ + if (TREE_CODE (decl) != VAR_DECL) + return; + + /* And only things with destructors need cleaning up. */ + if (type == error_mark_node + || TYPE_HAS_TRIVIAL_DESTRUCTOR (type)) + return; + + if (TREE_CODE (decl) == VAR_DECL && + (DECL_EXTERNAL (decl) || TREE_STATIC (decl))) + /* We don't clean up things that aren't defined in this + translation unit, or that need a static cleanup. The latter + are handled by finish_file. */ + return; + + /* Compute the cleanup. */ + cleanup = maybe_build_cleanup (decl); + + /* Record the cleanup required for this declaration. */ + if (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node + && cleanup) + finish_decl_cleanup (decl, cleanup); } /* Finish processing of a declaration; @@ -7734,40 +8041,23 @@ check_for_uninitialized_const_var (decl) If the length of an array type is not known before, it must be determined now, from the initial value, or it is an error. - Call `pop_obstacks' iff NEED_POP is nonzero. - - For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers - for aggregates that have constructors alive on the permanent obstack, - so that the global initializing functions can be written at the end. - - INIT0 holds the value of an initializer that should be allowed to escape + INIT holds the value of an initializer that should be allowed to escape the normal rules. - FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0 - if the (init) syntax was used. - - For functions that take default parameters, DECL points to its - "maximal" instantiation. `cp_finish_decl' must then also declared its - subsequently lower and lower forms of instantiation, checking for - ambiguity as it goes. This can be sped up later. */ + FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0 + if the (init) syntax was used. */ void -cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) +cp_finish_decl (decl, init, asmspec_tree, flags) tree decl, init; tree asmspec_tree; - int need_pop; int flags; { register tree type; - tree cleanup = NULL_TREE, ttype = NULL_TREE; - int was_incomplete; - int temporary = allocation_temporary_p (); - char *asmspec = NULL; + tree ttype = NULL_TREE; + const char *asmspec = NULL; int was_readonly = 0; - int already_used = 0; - tree core_type; - /* If this is 0, then we did not change obstacks. */ if (! decl) { if (init) @@ -7781,18 +8071,18 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) if (init && TREE_CODE (init) == NAMESPACE_DECL) { - cp_error ("Cannot initialize `%D' to namespace `%D'", + error ("cannot initialize `%D' to namespace `%D'", decl, init); init = NULL_TREE; } if (current_class_type - && DECL_REAL_CONTEXT (decl) == current_class_type + && CP_DECL_CONTEXT (decl) == current_class_type && TYPE_BEING_DEFINED (current_class_type) && (DECL_INITIAL (decl) || init)) - DECL_DEFINED_IN_CLASS_P (decl) = 1; + DECL_INITIALIZED_IN_CLASS_P (decl) = 1; - if (TREE_CODE (decl) == VAR_DECL + if (TREE_CODE (decl) == VAR_DECL && DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL && DECL_CONTEXT (decl) != current_namespace @@ -7802,46 +8092,29 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) pop_decl_namespace (); } - /* If the type of the thing we are declaring either has - a constructor, or has a virtual function table pointer, - AND its initialization was accepted by `start_decl', - then we stayed on the permanent obstack through the - declaration, otherwise, changed obstacks as GCC would. */ - type = TREE_TYPE (decl); if (type == error_mark_node) - { - if (toplevel_bindings_p () && temporary) - end_temporary_allocation (); - - return; - } + return; if (TYPE_HAS_MUTABLE_P (type)) TREE_READONLY (decl) = 0; - + if (processing_template_decl) { + /* Add this declaration to the statement-tree. */ + if (at_function_scope_p () + && TREE_CODE (decl) != RESULT_DECL) + add_decl_stmt (decl); + if (init && DECL_INITIAL (decl)) DECL_INITIAL (decl) = init; - if (minimal_parse_mode && ! DECL_ARTIFICIAL (decl)) - { - tree stmt = DECL_VINDEX (decl); - /* If the decl is declaring a member of a local class (in a - template function), the DECL_VINDEX will either be NULL, - or it will be an actual virtual function index, not a - DECL_STMT. */ - if (stmt != NULL_TREE && TREE_CODE (stmt) == DECL_STMT) - { - DECL_VINDEX (decl) = NULL_TREE; - TREE_OPERAND (stmt, 2) = copy_to_permanent (init); - add_tree (stmt); - } - } - goto finish_end0; } + + /* Parameters are handled by store_parm_decls, not cp_finish_decl. */ + my_friendly_assert (TREE_CODE (decl) != PARM_DECL, 19990828); + /* Take care of TYPE_DECLs up front. */ if (TREE_CODE (decl) == TYPE_DECL) { @@ -7855,7 +8128,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) && IS_AGGR_TYPE (type) && DECL_NAME (decl)) { if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type) - cp_warning ("shadowing previous type declaration of `%#D'", decl); + warning ("shadowing previous type declaration of `%#D'", decl); set_identifier_type_value (DECL_NAME (decl), type); CLASSTYPE_GOT_SEMICOLON (type) = 1; } @@ -7865,22 +8138,20 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) type, and that type has not been defined yet, delay emitting the debug information for it, as we will emit it later. */ if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl - && TYPE_SIZE (TREE_TYPE (decl)) == NULL_TREE) + && !COMPLETE_TYPE_P (TREE_TYPE (decl))) TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; - rest_of_decl_compilation (decl, NULL_PTR, + rest_of_decl_compilation (decl, NULL, DECL_CONTEXT (decl) == NULL_TREE, at_eof); goto finish_end; } + if (TREE_CODE (decl) != FUNCTION_DECL) - { - ttype = target_type (type); - } + ttype = target_type (type); if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) && TYPE_NEEDS_CONSTRUCTING (type)) { - /* Currently, GNU C++ puts constants in text space, making them impossible to initialize. In the future, one would hope for an operating system which understood the difference between @@ -7889,379 +8160,49 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) TREE_READONLY (decl) = 0; } - if (TREE_CODE (decl) == FIELD_DECL) + if (TREE_CODE (decl) == FIELD_DECL && asmspec) { - if (init && init != error_mark_node) - my_friendly_assert (TREE_PERMANENT (init), 147); - - if (asmspec) - { - /* This must override the asm specifier which was placed - by grokclassfn. Lay this out fresh. */ - DECL_RTL (TREE_TYPE (decl)) = NULL_RTX; - DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); - make_decl_rtl (decl, asmspec, 0); - } - } - /* If `start_decl' didn't like having an initialization, ignore it now. */ - else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) - init = NULL_TREE; - else if (DECL_EXTERNAL (decl)) - ; - else if (TREE_CODE (type) == REFERENCE_TYPE - || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type))) - { - if (TREE_STATIC (decl)) - make_decl_rtl (decl, NULL_PTR, - toplevel_bindings_p () - || pseudo_global_level_p ()); - grok_reference_init (decl, type, init); - init = NULL_TREE; - } - - GNU_xref_decl (current_function_decl, decl); - - core_type = type; - while (TREE_CODE (core_type) == ARRAY_TYPE) - core_type = TREE_TYPE (core_type); - - if (TREE_CODE (decl) == FIELD_DECL) - ; - else if (TREE_CODE (decl) == CONST_DECL) - { - my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); - - DECL_INITIAL (decl) = init; - - /* This will keep us from needing to worry about our obstacks. */ - my_friendly_assert (init != NULL_TREE, 149); - init = NULL_TREE; - } - else if (init) - { - if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type)) - { - if (TREE_CODE (type) == ARRAY_TYPE) - init = digest_init (type, init, (tree *) 0); - else if (TREE_CODE (init) == CONSTRUCTOR - && TREE_HAS_CONSTRUCTOR (init)) - { - if (TYPE_NON_AGGREGATE_CLASS (type)) - { - cp_error ("`%D' must be initialized by constructor, not by `{...}'", - decl); - init = error_mark_node; - } - else - goto dont_use_constructor; - } - } - else - { - dont_use_constructor: - if (TREE_CODE (init) != TREE_VEC) - init = store_init_value (decl, init); - } - - if (init) - /* We must hide the initializer so that expand_decl - won't try to do something it does not understand. */ - init = obscure_complex_init (decl, init); - } - else if (DECL_EXTERNAL (decl)) - ; - else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't' - && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))) - { - if (! TYPE_NEEDS_CONSTRUCTING (core_type)) - { - if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)) - cp_error ("structure `%D' with uninitialized const members", decl); - if (CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)) - cp_error ("structure `%D' with uninitialized reference members", - decl); - } - - check_for_uninitialized_const_var (decl); - - if (TYPE_SIZE (type) != NULL_TREE - && TYPE_NEEDS_CONSTRUCTING (type)) - init = obscure_complex_init (decl, NULL_TREE); - + /* This must override the asm specifier which was placed by + grokclassfn. Lay this out fresh. */ + SET_DECL_RTL (TREE_TYPE (decl), NULL_RTX); + SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec)); + make_decl_rtl (decl, asmspec); } - else - check_for_uninitialized_const_var (decl); - - /* For top-level declaration, the initial value was read in - the temporary obstack. MAXINDEX, rtl, etc. to be made below - must go in the permanent obstack; but don't discard the - temporary data yet. */ - - if (toplevel_bindings_p () && temporary) - end_temporary_allocation (); /* Deduce size of array from initialization, if not already known. */ + init = check_initializer (decl, init); + maybe_deduce_size_from_array_init (decl, init); - if (TREE_CODE (type) == ARRAY_TYPE - && TYPE_DOMAIN (type) == NULL_TREE - && TREE_CODE (decl) != TYPE_DECL) - { - int do_default - = (TREE_STATIC (decl) - /* Even if pedantic, an external linkage array - may have incomplete type at first. */ - ? pedantic && ! DECL_EXTERNAL (decl) - : !DECL_EXTERNAL (decl)); - tree initializer = init ? init : DECL_INITIAL (decl); - int failure = complete_array_type (type, initializer, do_default); - - if (failure == 1) - cp_error ("initializer fails to determine size of `%D'", decl); - - if (failure == 2) - { - if (do_default) - cp_error ("array size missing in `%D'", decl); - /* If a `static' var's size isn't known, make it extern as - well as static, so it does not get allocated. If it's not - `static', then don't mark it extern; finish_incomplete_decl - will give it a default size and it will get allocated. */ - else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) - DECL_EXTERNAL (decl) = 1; - } - - if (pedantic && TYPE_DOMAIN (type) != NULL_TREE - && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), - integer_zero_node)) - cp_error ("zero-size array `%D'", decl); + GNU_xref_decl (current_function_decl, decl); - layout_decl (decl, 0); - } + /* Add this declaration to the statement-tree. This needs to happen + after the call to check_initializer so that the DECL_STMT for a + reference temp is added before the DECL_STMT for the reference itself. */ + if (building_stmt_tree () + && at_function_scope_p () + && TREE_CODE (decl) != RESULT_DECL) + add_decl_stmt (decl); if (TREE_CODE (decl) == VAR_DECL) - { - if (DECL_SIZE (decl) == NULL_TREE - && TYPE_SIZE (complete_type (TREE_TYPE (decl))) != NULL_TREE) - layout_decl (decl, 0); - - if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) - { - /* A static variable with an incomplete type: - that is an error if it is initialized. - Otherwise, let it through, but if it is not `extern' - then it may cause an error message later. */ - if (DECL_INITIAL (decl) != NULL_TREE) - cp_error ("storage size of `%D' isn't known", decl); - init = NULL_TREE; - } - else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) - { - /* An automatic variable with an incomplete type: that is an error. - Don't talk about array types here, since we took care of that - message in grokdeclarator. */ - cp_error ("storage size of `%D' isn't known", decl); - TREE_TYPE (decl) = error_mark_node; - } - else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) - /* Let debugger know it should output info for this type. */ - note_debug_info_needed (ttype); - - if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl)) - note_debug_info_needed (DECL_CONTEXT (decl)); - - if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) - && DECL_SIZE (decl) != NULL_TREE - && ! TREE_CONSTANT (DECL_SIZE (decl))) - { - if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) - constant_expression_warning (DECL_SIZE (decl)); - else - cp_error ("storage size of `%D' isn't constant", decl); - } - - if (! DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type) - /* Cleanups for static variables are handled by `finish_file'. */ - && ! TREE_STATIC (decl)) - { - int yes = suspend_momentary (); - cleanup = maybe_build_cleanup (decl); - resume_momentary (yes); - } - } - /* PARM_DECLs get cleanups, too. */ - else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type)) - { - if (temporary) - end_temporary_allocation (); - cleanup = maybe_build_cleanup (decl); - if (temporary) - resume_temporary_allocation (); - } + layout_var_decl (decl); /* Output the assembler code and/or RTL code for variables and functions, unless the type is an undefined structure or union. If not, it will get done when the type is completed. */ - - was_incomplete = (DECL_SIZE (decl) == NULL_TREE); - if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == RESULT_DECL) { - /* ??? FIXME: What about nested classes? */ - int toplev = toplevel_bindings_p () || pseudo_global_level_p (); - int was_temp - = (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type) - && allocation_temporary_p ()); - - if (was_temp) - end_temporary_allocation (); - - /* Static data in a function with comdat linkage also has comdat - linkage. */ - if (TREE_CODE (decl) == VAR_DECL - && TREE_STATIC (decl) - /* Don't mess with __FUNCTION__. */ - && ! TREE_ASM_WRITTEN (decl) - && current_function_decl - && DECL_CONTEXT (decl) == current_function_decl - && (DECL_THIS_INLINE (current_function_decl) - || DECL_TEMPLATE_INSTANTIATION (current_function_decl)) - && TREE_PUBLIC (current_function_decl)) - { - /* Rather than try to get this right with inlining, we suppress - inlining of such functions. */ - current_function_cannot_inline - = "function with static variable cannot be inline"; - - /* If flag_weak, we don't need to mess with this, as we can just - make the function weak, and let it refer to its unique local - copy. This works because we don't allow the function to be - inlined. */ - if (! flag_weak) - { - if (DECL_INTERFACE_KNOWN (current_function_decl)) - { - TREE_PUBLIC (decl) = 1; - DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl); - } - else if (DECL_INITIAL (decl) == NULL_TREE - || DECL_INITIAL (decl) == error_mark_node) - { - TREE_PUBLIC (decl) = 1; - DECL_COMMON (decl) = 1; - } - /* else we lose. We can only do this if we can use common, - which we can't if it has been initialized. */ - - if (TREE_PUBLIC (decl)) - DECL_ASSEMBLER_NAME (decl) - = build_static_name (current_function_decl, DECL_NAME (decl)); - else if (! DECL_ARTIFICIAL (decl)) - { - cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl); - cp_warning_at (" you can work around this by removing the initializer", decl); - } - } - } + if (TREE_CODE (decl) == VAR_DECL) + maybe_commonize_var (decl); - else if (TREE_CODE (decl) == VAR_DECL - && DECL_LANG_SPECIFIC (decl) - && DECL_COMDAT (decl)) - /* Set it up again; we might have set DECL_INITIAL since the - last time. */ - comdat_linkage (decl); + make_rtl_for_nonlocal_decl (decl, init, asmspec); - if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) - make_decl_rtl (decl, NULL_PTR, toplev); - else if (TREE_CODE (decl) == VAR_DECL - && TREE_READONLY (decl) - && DECL_INITIAL (decl) != NULL_TREE - && DECL_INITIAL (decl) != error_mark_node - && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) - { - DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); - - if (asmspec) - DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); - - if (! toplev - && TREE_STATIC (decl) - && ! TREE_SIDE_EFFECTS (decl) - && ! TREE_PUBLIC (decl) - && ! DECL_EXTERNAL (decl) - && ! TYPE_NEEDS_DESTRUCTOR (type) - && DECL_MODE (decl) != BLKmode) - { - /* If this variable is really a constant, then fill its DECL_RTL - slot with something which won't take up storage. - If something later should take its address, we can always give - it legitimate RTL at that time. */ - DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); - store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0); - TREE_ASM_WRITTEN (decl) = 1; - } - else if (toplev && ! TREE_PUBLIC (decl)) - { - /* If this is a static const, change its apparent linkage - if it belongs to a #pragma interface. */ - if (!interface_unknown) - { - TREE_PUBLIC (decl) = 1; - DECL_EXTERNAL (decl) = interface_only; - } - make_decl_rtl (decl, asmspec, toplev); - } - else - rest_of_decl_compilation (decl, asmspec, toplev, at_eof); - } - else if (TREE_CODE (decl) == VAR_DECL - && DECL_LANG_SPECIFIC (decl) - && DECL_IN_AGGR_P (decl)) - { - if (TREE_STATIC (decl)) - { - if (init == NULL_TREE -#ifdef DEFAULT_STATIC_DEFS - /* If this code is dead, then users must - explicitly declare static member variables - outside the class def'n as well. */ - && TYPE_NEEDS_CONSTRUCTING (type) -#endif - ) - { - DECL_EXTERNAL (decl) = 1; - make_decl_rtl (decl, asmspec, 1); - } - else - rest_of_decl_compilation (decl, asmspec, toplev, at_eof); - } - else - /* Just a constant field. Should not need any rtl. */ - goto finish_end0; - } + if (TREE_CODE (type) == FUNCTION_TYPE + || TREE_CODE (type) == METHOD_TYPE) + abstract_virtuals_error (decl, + strip_array_types (TREE_TYPE (type))); else - rest_of_decl_compilation (decl, asmspec, toplev, at_eof); - - if (was_temp) - resume_temporary_allocation (); - - if (type != error_mark_node - && TYPE_LANG_SPECIFIC (core_type) - && CLASSTYPE_ABSTRACT_VIRTUALS (core_type)) - abstract_virtuals_error (decl, core_type); - else if ((TREE_CODE (type) == FUNCTION_TYPE - || TREE_CODE (type) == METHOD_TYPE) - && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) - && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type))) - abstract_virtuals_error (decl, TREE_TYPE (type)); - - if (TYPE_LANG_SPECIFIC (core_type) && IS_SIGNATURE (core_type)) - signature_error (decl, core_type); - else if ((TREE_CODE (type) == FUNCTION_TYPE - || TREE_CODE (type) == METHOD_TYPE) - && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) - && IS_SIGNATURE (TREE_TYPE (type))) - signature_error (decl, TREE_TYPE (type)); + abstract_virtuals_error (decl, strip_array_types (type)); if (TREE_CODE (decl) == FUNCTION_DECL) ; @@ -8272,137 +8213,46 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) if (init) DECL_INITIAL (decl) = init; } - else if (TREE_STATIC (decl) && type != error_mark_node) + else if (TREE_CODE (CP_DECL_CONTEXT (decl)) == FUNCTION_DECL) { - /* Cleanups for static variables are handled by `finish_file'. */ - if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE - || TYPE_NEEDS_DESTRUCTOR (type)) - expand_static_init (decl, init); - } - else if (! toplev) - { - /* This is a declared decl which must live until the - end of the binding contour. It may need a cleanup. */ - - /* Recompute the RTL of a local array now - if it used to be an incomplete type. */ - if (was_incomplete && ! TREE_STATIC (decl)) - { - /* If we used it already as memory, it must stay in memory. */ - TREE_ADDRESSABLE (decl) = TREE_USED (decl); - /* If it's still incomplete now, no init will save it. */ - if (DECL_SIZE (decl) == NULL_TREE) - DECL_INITIAL (decl) = NULL_TREE; - expand_decl (decl); - } - else if (! TREE_ASM_WRITTEN (decl) - && (TYPE_SIZE (type) != NULL_TREE - || TREE_CODE (type) == ARRAY_TYPE)) + /* This is a local declaration. */ + if (doing_semantic_analysis_p ()) + maybe_inject_for_scope_var (decl); + /* Initialize the local variable. But, if we're building a + statement-tree, we'll do the initialization when we + expand the tree. */ + if (processing_template_decl) { - /* Do this here, because we did not expand this decl's - rtl in start_decl. */ - if (DECL_RTL (decl) == NULL_RTX) - expand_decl (decl); - else if (cleanup) - { - /* XXX: Why don't we use decl here? */ - /* Ans: Because it was already expanded? */ - if (! expand_decl_cleanup (NULL_TREE, cleanup)) - cp_error ("parser lost in parsing declaration of `%D'", - decl); - /* Cleanup used up here. */ - cleanup = NULL_TREE; - } + if (init || DECL_INITIAL (decl) == error_mark_node) + DECL_INITIAL (decl) = init; } - - if (current_binding_level->is_for_scope) - { - struct binding_level *outer - = current_binding_level->level_chain; - - /* Check to see if the same name is already bound at - the outer level, either because it was directly declared, - or because a dead for-decl got preserved. In either case, - the code would not have been valid under the ARM - scope rules, so clear is_for_scope for the - current_binding_level. - - Otherwise, we need to preserve the temp slot for decl - to last into the outer binding level. */ - - tree outer_binding - = TREE_CHAIN (IDENTIFIER_BINDING (DECL_NAME (decl))); - - if (outer_binding && BINDING_LEVEL (outer_binding) == outer - && (TREE_CODE (BINDING_VALUE (outer_binding)) - == VAR_DECL) - && DECL_DEAD_FOR_LOCAL (BINDING_VALUE (outer_binding))) - { - BINDING_VALUE (outer_binding) - = DECL_SHADOWED_FOR_VAR (BINDING_VALUE (outer_binding)); - current_binding_level->is_for_scope = 0; - } - else if (DECL_IN_MEMORY_P (decl)) - preserve_temp_slots (DECL_RTL (decl)); - } - - expand_start_target_temps (); - - if (DECL_SIZE (decl) && type != error_mark_node) - { - /* Compute and store the initial value. */ - expand_decl_init (decl); - already_used = TREE_USED (decl) || TREE_USED (type); - - if (init || TYPE_NEEDS_CONSTRUCTING (type)) - { - emit_line_note (DECL_SOURCE_FILE (decl), - DECL_SOURCE_LINE (decl)); - expand_aggr_init (decl, init, flags); - } - - /* Set this to 0 so we can tell whether an aggregate which - was initialized was ever used. Don't do this if it has a - destructor, so we don't complain about the 'resource - allocation is initialization' idiom. */ - /* Now set attribute((unused)) on types so decls of - that type will be marked used. (see TREE_USED, above.) - This avoids the warning problems this particular code - tried to work around. */ - - if (TYPE_NEEDS_CONSTRUCTING (type) - && ! already_used - && cleanup == NULL_TREE - && DECL_NAME (decl)) - TREE_USED (decl) = 0; - - if (already_used) - TREE_USED (decl) = 1; - } - - /* Cleanup any temporaries needed for the initial value. */ - expand_end_target_temps (); - - if (DECL_SIZE (decl) && type != error_mark_node) + else { - /* Store the cleanup, if there was one. */ - if (cleanup) - { - if (! expand_decl_cleanup (decl, cleanup)) - cp_error ("parser lost in parsing declaration of `%D'", - decl); - } + /* If we're not building RTL, then we need to do so + now. */ + my_friendly_assert (building_stmt_tree (), 20000906); + /* Initialize the variable. */ + initialize_local_var (decl, init, flags); + /* Clean up the variable. */ + destroy_local_var (decl); } } + else if (TREE_STATIC (decl) && type != error_mark_node) + { + /* Cleanups for static variables are handled by `finish_file'. */ + if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE + || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) + expand_static_init (decl, init); + } finish_end0: /* Undo call to `pushclass' that was done in `start_decl' due to initialization of qualified member variable. I.e., Foo::x = 10; */ { - tree context = DECL_REAL_CONTEXT (decl); + tree context = CP_DECL_CONTEXT (decl); if (context - && TREE_CODE_CLASS (TREE_CODE (context)) == 't' + && TYPE_P (context) && (TREE_CODE (decl) == VAR_DECL /* We also have a pushclass done that we need to undo here if we're at top level and declare a method. */ @@ -8410,7 +8260,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) /* If size hasn't been set, we're still defining it, and therefore inside the class body; don't pop the binding level.. */ - && TYPE_SIZE (context) != NULL_TREE + && COMPLETE_TYPE_P (context) && context == current_class_type) pop_nested_class (); } @@ -8418,44 +8268,253 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) finish_end: - /* If requested, warn about definitions of large data objects. */ + if (was_readonly) + TREE_READONLY (decl) = 1; +} + +/* This is here for a midend callback from c-common.c */ + +void +finish_decl (decl, init, asmspec_tree) + tree decl, init; + tree asmspec_tree; +{ + cp_finish_decl (decl, init, asmspec_tree, 0); +} - if (warn_larger_than - && ! processing_template_decl - && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) - && !DECL_EXTERNAL (decl)) +/* Returns a declaration for a VAR_DECL as if: + + extern "C" TYPE NAME; + + had been seen. Used to create compiler-generated global + variables. */ + +tree +declare_global_var (name, type) + tree name; + tree type; +{ + tree decl; + + push_to_top_level (); + decl = build_decl (VAR_DECL, name, type); + TREE_PUBLIC (decl) = 1; + DECL_EXTERNAL (decl) = 1; + DECL_ARTIFICIAL (decl) = 1; + pushdecl (decl); + cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0); + pop_from_top_level (); + + return decl; +} + +/* Returns a pointer to the `atexit' function. Note that if + FLAG_USE_CXA_ATEXIT is non-zero, then this will actually be the new + `__cxa_atexit' function specified in the IA64 C++ ABI. */ + +static tree +get_atexit_node () +{ + tree atexit_fndecl; + tree arg_types; + tree fn_type; + tree fn_ptr_type; + const char *name; + + if (atexit_node) + return atexit_node; + + if (flag_use_cxa_atexit) { - register tree decl_size = DECL_SIZE (decl); + /* The declaration for `__cxa_atexit' is: - if (decl_size && TREE_CODE (decl_size) == INTEGER_CST) - { - unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT; + int __cxa_atexit (void (*)(void *), void *, void *) - if (units > larger_than_size) - warning_with_decl (decl, "size of `%s' is %u bytes", units); - } + We build up the argument types and then then function type + itself. */ + + /* First, build the pointer-to-function type for the first + argument. */ + arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node); + fn_type = build_function_type (void_type_node, arg_types); + fn_ptr_type = build_pointer_type (fn_type); + /* Then, build the rest of the argument types. */ + arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node); + arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types); + arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types); + /* And the final __cxa_atexit type. */ + fn_type = build_function_type (integer_type_node, arg_types); + fn_ptr_type = build_pointer_type (fn_type); + name = "__cxa_atexit"; + } + else + { + /* The declaration for `atexit' is: + + int atexit (void (*)()); + + We build up the argument types and then then function type + itself. */ + fn_type = build_function_type (void_type_node, void_list_node); + fn_ptr_type = build_pointer_type (fn_type); + arg_types = tree_cons (NULL_TREE, fn_ptr_type, void_list_node); + /* Build the final atexit type. */ + fn_type = build_function_type (integer_type_node, arg_types); + name = "atexit"; } - if (need_pop) + /* Now, build the function declaration. */ + push_lang_context (lang_name_c); + atexit_fndecl = build_library_fn_ptr (name, fn_type); + mark_used (atexit_fndecl); + pop_lang_context (); + atexit_node = default_conversion (atexit_fndecl); + + return atexit_node; +} + +/* Returns the __dso_handle VAR_DECL. */ + +static tree +get_dso_handle_node () +{ + if (dso_handle_node) + return dso_handle_node; + + /* Declare the variable. */ + dso_handle_node = declare_global_var (get_identifier ("__dso_handle"), + ptr_type_node); + + return dso_handle_node; +} + +/* Begin a new function with internal linkage whose job will be simply + to destroy some particular variable. */ + +static tree +start_cleanup_fn () +{ + static int counter = 0; + int old_interface_unknown = interface_unknown; + char name[32]; + tree parmtypes; + tree fntype; + tree fndecl; + + push_to_top_level (); + + /* No need to mangle this. */ + push_lang_context (lang_name_c); + + interface_unknown = 1; + + /* Build the parameter-types. */ + parmtypes = void_list_node; + /* Functions passed to __cxa_atexit take an additional parameter. + We'll just ignore it. After we implement the new calling + convention for destructors, we can eliminate the use of + additional cleanup functions entirely in the -fnew-abi case. */ + if (flag_use_cxa_atexit) + parmtypes = tree_cons (NULL_TREE, ptr_type_node, parmtypes); + /* Build the function type itself. */ + fntype = build_function_type (void_type_node, parmtypes); + /* Build the name of the function. */ + sprintf (name, "__tcf_%d", counter++); + /* Build the function declaration. */ + fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype); + /* It's a function with internal linkage, generated by the + compiler. */ + TREE_PUBLIC (fndecl) = 0; + DECL_ARTIFICIAL (fndecl) = 1; + /* Make the function `inline' so that it is only emitted if it is + actually needed. It is unlikely that it will be inlined, since + it is only called via a function pointer, but we avoid unnecessary + emissions this way. */ + DECL_INLINE (fndecl) = 1; + /* Build the parameter. */ + if (flag_use_cxa_atexit) { - /* Resume permanent allocation, if not within a function. */ - /* The corresponding push_obstacks_nochange is in start_decl, - start_method, groktypename, and in grokfield. */ - pop_obstacks (); + tree parmdecl; + + parmdecl = build_decl (PARM_DECL, NULL_TREE, ptr_type_node); + DECL_CONTEXT (parmdecl) = fndecl; + DECL_ARG_TYPE (parmdecl) = ptr_type_node; + TREE_USED (parmdecl) = 1; + DECL_ARGUMENTS (fndecl) = parmdecl; } - if (was_readonly) - TREE_READONLY (decl) = 1; + pushdecl (fndecl); + start_function (/*specs=*/NULL_TREE, fndecl, NULL_TREE, SF_PRE_PARSED); + + interface_unknown = old_interface_unknown; + + pop_lang_context (); + + return current_function_decl; } -/* This is here for a midend callback from c-common.c */ +/* Finish the cleanup function begun by start_cleanup_fn. */ + +static void +end_cleanup_fn () +{ + expand_body (finish_function (0)); + + pop_from_top_level (); +} + +/* Generate code to handle the destruction of DECL, an object with + static storage duration. */ void -finish_decl (decl, init, asmspec_tree) - tree decl, init; - tree asmspec_tree; +register_dtor_fn (decl) + tree decl; { - cp_finish_decl (decl, init, asmspec_tree, 1, 0); + tree cleanup; + tree compound_stmt; + tree args; + tree fcall; + + int saved_flag_access_control; + + if (TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl))) + return; + + /* Call build_cleanup before we enter the anonymous function so that + any access checks will be done relative to the current scope, + rather than the scope of the anonymous function. */ + build_cleanup (decl); + + /* Now start the function. */ + cleanup = start_cleanup_fn (); + + /* Now, recompute the cleanup. It may contain SAVE_EXPRs that refer + to the original function, rather than the anonymous one. That + will make the back-end think that nested functions are in use, + which causes confusion. */ + saved_flag_access_control = flag_access_control; + flag_access_control = 0; + fcall = build_cleanup (decl); + flag_access_control = saved_flag_access_control; + + /* Create the body of the anonymous function. */ + compound_stmt = begin_compound_stmt (/*has_no_scope=*/0); + finish_expr_stmt (fcall); + finish_compound_stmt (/*has_no_scope=*/0, compound_stmt); + end_cleanup_fn (); + + /* Call atexit with the cleanup function. */ + mark_addressable (cleanup); + cleanup = build_unary_op (ADDR_EXPR, cleanup, 0); + if (flag_use_cxa_atexit) + { + args = tree_cons (NULL_TREE, get_dso_handle_node (), NULL_TREE); + args = tree_cons (NULL_TREE, null_pointer_node, args); + args = tree_cons (NULL_TREE, cleanup, args); + } + else + args = tree_cons (NULL_TREE, cleanup, NULL_TREE); + finish_expr_stmt (build_function_call (get_atexit_node (), args)); } void @@ -8468,23 +8527,24 @@ expand_static_init (decl, init) if (oldstatic) { if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) - cp_error ("multiple initializations given for `%D'", decl); + error ("multiple initializations given for `%D'", decl); } else if (! toplevel_bindings_p ()) { /* Emit code to perform this initialization but once. */ - tree temp; - - /* Remember this information until end of file. */ - push_obstacks (&permanent_obstack, &permanent_obstack); + tree if_stmt; + tree then_clause; + tree assignment; + tree guard; + tree guard_init; /* Emit code to perform this initialization but once. This code looks like: - static int temp = 0; - if (!temp) { + static int guard = 0; + if (!guard) { // Do initialization. - temp = 1; + guard = 1; // Register variable for destruction at end of program. } @@ -8492,7 +8552,7 @@ expand_static_init (decl, init) initialization is complete. This ensures that an exception, thrown during the construction, will cause the variable to reinitialized when we pass through this code again, as per: - + [stmt.dcl] If the initialization exits by throwing an exception, the @@ -8502,110 +8562,79 @@ expand_static_init (decl, init) In theory, this process should be thread-safe, too; multiple threads should not be able to initialize the variable more than once. We don't yet attempt to ensure thread-safety. */ - temp = get_temp_name (integer_type_node, 1); - rest_of_decl_compilation (temp, NULL_PTR, 0, 0); + + /* Create the guard variable. */ + guard = get_guard (decl); /* Begin the conditional initialization. */ - expand_start_cond (build_binary_op (EQ_EXPR, temp, - integer_zero_node), 0); - expand_start_target_temps (); + if_stmt = begin_if_stmt (); + finish_if_stmt_cond (get_guard_cond (guard), if_stmt); + then_clause = begin_compound_stmt (/*has_no_scope=*/0); /* Do the initialization itself. */ if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)) || (init && TREE_CODE (init) == TREE_LIST)) - { - expand_aggr_init (decl, init, 0); - do_pending_stack_adjust (); - } + assignment = build_aggr_init (decl, init, 0); else if (init) - expand_assignment (decl, init, 0, 0); - - /* Set TEMP to 1. */ - expand_assignment (temp, integer_one_node, 0, 0); - - /* Cleanup any temporaries needed for the initial value. If - destroying one of the temporaries causes an exception to be - thrown, then the object itself has still been fully - constructed. */ - expand_end_target_temps (); + /* The initialization we're doing here is just a bitwise + copy. */ + assignment = build (INIT_EXPR, TREE_TYPE (decl), decl, init); + else + assignment = NULL_TREE; + + /* Once the assignment is complete, set TEMP to 1. Since the + construction of the static object is complete at this point, + we want to make sure TEMP is set to 1 even if a temporary + constructed during the initialization throws an exception + when it is destroyed. So, we combine the initialization and + the assignment to TEMP into a single expression, ensuring + that when we call finish_expr_stmt the cleanups will not be + run until after TEMP is set to 1. */ + guard_init = set_guard (guard); + if (assignment) + { + assignment = tree_cons (NULL_TREE, assignment, + build_tree_list (NULL_TREE, + guard_init)); + assignment = build_compound_expr (assignment); + } + else + assignment = guard_init; + finish_expr_stmt (assignment); /* Use atexit to register a function for destroying this static variable. */ - if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) - { - tree cleanup, fcall; - static tree Atexit = 0; - int saved_flag_access_control; + register_dtor_fn (decl); - if (Atexit == 0) - { - tree atexit_fndecl, PFV, pfvlist; - /* Remember this information until end of file. */ - push_obstacks (&permanent_obstack, &permanent_obstack); - PFV = build_pointer_type (build_function_type - (void_type_node, void_list_node)); - - pfvlist = tree_cons (NULL_TREE, PFV, void_list_node); - - push_lang_context (lang_name_c); - atexit_fndecl - = builtin_function ("atexit", - build_function_type (void_type_node, - pfvlist), - NOT_BUILT_IN, NULL_PTR); - mark_used (atexit_fndecl); - Atexit = default_conversion (atexit_fndecl); - pop_lang_context (); - pop_obstacks (); - } - - /* Call build_cleanup before we enter the anonymous function - so that any access checks will be done relative to the - current scope, rather than the scope of the anonymous - function. */ - build_cleanup (decl); - - /* Now start the function. */ - cleanup = start_anon_func (); - - /* Now, recompute the cleanup. It may contain SAVE_EXPRs - that refer to the original function, rather than the - anonymous one. That will make the back-end think that - nested functions are in use, which causes confusion. */ - saved_flag_access_control = flag_access_control; - flag_access_control = 0; - fcall = build_cleanup (decl); - flag_access_control = saved_flag_access_control; - - /* Finish off the function. */ - expand_expr_stmt (fcall); - end_anon_func (); - - /* Call atexit with the cleanup function. */ - mark_addressable (cleanup); - cleanup = build_unary_op (ADDR_EXPR, cleanup, 0); - fcall = build_function_call (Atexit, - expr_tree_cons (NULL_TREE, - cleanup, - NULL_TREE)); - expand_expr_stmt (fcall); - } - - expand_end_cond (); - /* Resume old (possibly temporary) allocation. */ - pop_obstacks (); + finish_compound_stmt (/*has_no_scope=*/0, then_clause); + finish_then_clause (if_stmt); + finish_if_stmt (); } else + static_aggregates = tree_cons (init, decl, static_aggregates); +} + +/* Finish the declaration of a catch-parameter. */ + +tree +start_handler_parms (declspecs, declarator) + tree declspecs; + tree declarator; +{ + tree decl; + if (declspecs) { - /* This code takes into account memory allocation policy of - `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING does not - hold for this object, then we must make permanent the storage - currently in the temporary obstack. */ - if (!TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) - preserve_initializer (); - static_aggregates = perm_tree_cons (init, decl, static_aggregates); + decl = grokdeclarator (declarator, declspecs, CATCHPARM, + 1, NULL); + if (decl == NULL_TREE) + error ("invalid catch parameter"); } + else + decl = NULL_TREE; + + return decl; } + /* Make TYPE a complete type based on INITIAL_VALUE. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, @@ -8618,14 +8647,21 @@ complete_array_type (type, initial_value, do_default) { register tree maxindex = NULL_TREE; int value = 0; - - /* Allocate on the same obstack as TYPE. */ - push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); - + if (initial_value) { - /* Note MAXINDEX is really the maximum index, - one less than the size. */ + /* An array of character type can be initialized from a + brace-enclosed string constant. */ + if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))) + && TREE_CODE (initial_value) == CONSTRUCTOR + && CONSTRUCTOR_ELTS (initial_value) + && (TREE_CODE (TREE_VALUE (CONSTRUCTOR_ELTS (initial_value))) + == STRING_CST) + && TREE_CHAIN (CONSTRUCTOR_ELTS (initial_value)) == NULL_TREE) + initial_value = TREE_VALUE (CONSTRUCTOR_ELTS (initial_value)); + + /* Note MAXINDEX is really the maximum index, one less than the + size. */ if (TREE_CODE (initial_value) == STRING_CST) { int eltsize @@ -8636,13 +8672,14 @@ complete_array_type (type, initial_value, do_default) else if (TREE_CODE (initial_value) == CONSTRUCTOR) { tree elts = CONSTRUCTOR_ELTS (initial_value); - maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node); + + maxindex = ssize_int (-1); for (; elts; elts = TREE_CHAIN (elts)) { if (TREE_PURPOSE (elts)) maxindex = TREE_PURPOSE (elts); else - maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node); + maxindex = size_binop (PLUS_EXPR, maxindex, ssize_int (1)); } maxindex = copy_node (maxindex); } @@ -8689,8 +8726,6 @@ complete_array_type (type, initial_value, do_default) TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = domain; } - pop_obstacks(); - /* Lay out the type now that we can get the real answer. */ layout_type (type); @@ -8703,13 +8738,18 @@ complete_array_type (type, initial_value, do_default) message to print in that case. Otherwise, quietly return 1. */ static int -member_function_or_else (ctype, cur_type, string) +member_function_or_else (ctype, cur_type, flags) tree ctype, cur_type; - const char *string; + enum overload_flags flags; { if (ctype && ctype != cur_type) { - error (string, TYPE_NAME_STRING (ctype)); + if (flags == DTOR_FLAG) + error ("destructor for alien class `%T' cannot be a member", + ctype); + else + error ("constructor for alien class `%T' cannot be a member", + ctype); return 0; } return 1; @@ -8727,16 +8767,20 @@ bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) int virtualp, quals, friendp, raises, inlinep; { if (virtualp) - cp_error ("`%D' declared as a `virtual' %s", object, type); + error ("`%D' declared as a `virtual' %s", object, type); if (inlinep) - cp_error ("`%D' declared as an `inline' %s", object, type); + error ("`%D' declared as an `inline' %s", object, type); if (quals) - cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", + error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", object, type); if (friendp) - cp_error_at ("invalid friend declaration", object); - if (raises) - cp_error_at ("invalid exception specifications", object); + cp_error_at ("`%D' declared as a friend", object); + if (raises + && (TREE_CODE (object) == TYPE_DECL + || (!TYPE_PTRFN_P (TREE_TYPE (object)) + && !TYPE_REFFN_P (TREE_TYPE (object)) + && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object))))) + cp_error_at ("`%D' declared with an exception specification", object); } /* CTYPE is class type, or null if non-class. @@ -8749,7 +8793,7 @@ bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) or `volatile'. RAISES is a list of exceptions that this function can raise. CHECK is 1 if we must find this method in CTYPE, 0 if we should - not look, and -1 if we should not call `grokclassfn' at all. + not look, and -1 if we should not call `grokclassfn' at all. Returns `NULL_TREE' if something goes wrong, after issuing applicable error messages. */ @@ -8767,21 +8811,13 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, int check, friendp, publicp, inlinep, funcdef_flag, template_count; tree in_namespace; { - tree cname, decl; + tree decl; int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; int has_default_arg = 0; tree t; - if (ctype) - cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL - ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype); - else - cname = NULL_TREE; - if (raises) - { - type = build_exception_variant (type, raises); - } + type = build_exception_variant (type, raises); decl = build_lang_decl (FUNCTION_DECL, declarator, type); /* Propagate volatile out from type to decl. */ @@ -8791,7 +8827,7 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, /* If this decl has namespace scope, set that up. */ if (in_namespace) set_decl_namespace (decl, in_namespace, friendp); - else if (publicp && ! ctype) + else if (!ctype) DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); /* `main' and builtins have implicit 'C' linkage. */ @@ -8804,7 +8840,7 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, && ctype == NULL_TREE /* NULL_TREE means global namespace. */ && DECL_CONTEXT (decl) == NULL_TREE) - DECL_LANGUAGE (decl) = lang_c; + SET_DECL_LANGUAGE (decl, lang_c); /* Should probably propagate const out from type to decl I bet (mrs). */ if (staticp) @@ -8814,24 +8850,28 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, } if (ctype) - DECL_CLASS_CONTEXT (decl) = ctype; + DECL_CONTEXT (decl) = ctype; if (ctype == NULL_TREE && DECL_MAIN_P (decl)) { if (processing_template_decl) - error ("cannot declare `main' to be a template"); + error ("cannot declare `::main' to be a template"); if (inlinep) - error ("cannot declare `main' to be inline"); - else if (! publicp) - error ("cannot declare `main' to be static"); + error ("cannot declare `::main' to be inline"); + if (!publicp) + error ("cannot declare `::main' to be static"); + if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)), + integer_type_node)) + error ("`main' must return `int'"); inlinep = 0; publicp = 1; } /* Members of anonymous types and local classes have no linkage; make them internal. */ - if (ctype && (ANON_AGGRNAME_P (TYPE_IDENTIFIER (ctype)) - || hack_decl_function_context (TYPE_MAIN_DECL (ctype)))) + /* FIXME what if it gets a name from typedef? */ + if (ctype && (TYPE_ANONYMOUS_P (ctype) + || decl_function_context (TYPE_MAIN_DECL (ctype)))) publicp = 0; if (publicp) @@ -8844,16 +8884,22 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, t = no_linkage_check (TREE_TYPE (decl)); if (t) { - if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) + if (TYPE_ANONYMOUS_P (t)) { - if (DECL_LANGUAGE (decl) == lang_c) + if (DECL_EXTERN_C_P (decl)) /* Allow this; it's pretty common in C. */; else - cp_pedwarn ("non-local function `%#D' uses anonymous type", - decl); + { + pedwarn ("non-local function `%#D' uses anonymous type", + decl); + if (DECL_ORIGINAL_TYPE (TYPE_NAME (t))) + cp_pedwarn_at ("\ +`%#D' does not refer to the unqualified type, so it is not used for linkage", + TYPE_NAME (t)); + } } else - cp_pedwarn ("non-local function `%#D' uses local type `%T'", + pedwarn ("non-local function `%#D' uses local type `%T'", decl, t); } } @@ -8865,21 +8911,26 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, DECL_NOT_REALLY_EXTERN (decl) = 1; } + /* If the declaration was declared inline, mark it as such. */ if (inlinep) - DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1; + DECL_DECLARED_INLINE_P (decl) = 1; + /* We inline functions that are explicitly declared inline, or, when + the user explicitly asks us to, all functions. */ + if (DECL_DECLARED_INLINE_P (decl) || flag_inline_trees == 2) + DECL_INLINE (decl) = 1; DECL_EXTERNAL (decl) = 1; if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) { - cp_error ("%smember function `%D' cannot have `%T' method qualifier", + error ("%smember function `%D' cannot have `%T' method qualifier", (ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); quals = NULL_TREE; } if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) - grok_op_properties (decl, virtualp, check < 0); + grok_op_properties (decl, friendp); - if (ctype && hack_decl_function_context (decl)) + if (ctype && decl_function_context (decl)) DECL_NO_STATIC_CHAIN (decl) = 1; for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t)) @@ -8894,15 +8945,18 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR) { if (funcdef_flag) - cp_error + error ("defining explicit specialization `%D' in friend declaration", orig_declarator); else { + tree fns = TREE_OPERAND (orig_declarator, 0); + tree args = TREE_OPERAND (orig_declarator, 1); + if (PROCESSING_REAL_TEMPLATE_DECL_P ()) { /* Something like `template <class T> friend void f<T>()'. */ - cp_error ("template-id `%D' in declaration of primary template", + error ("invalid use of template-id `%D' in declaration of primary template", orig_declarator); return NULL_TREE; } @@ -8911,21 +8965,33 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, /* A friend declaration of the form friend void f<>(). Record the information in the TEMPLATE_ID_EXPR. */ SET_DECL_IMPLICIT_INSTANTIATION (decl); - DECL_TEMPLATE_INFO (decl) - = perm_tree_cons (TREE_OPERAND (orig_declarator, 0), - TREE_OPERAND (orig_declarator, 1), - NULL_TREE); + + if (TREE_CODE (fns) == COMPONENT_REF) + { + /* Due to bison parser ickiness, we will have already looked + up an operator_name or PFUNCNAME within the current class + (see template_id in parse.y). If the current class contains + such a name, we'll get a COMPONENT_REF here. Undo that. */ + + my_friendly_assert (TREE_TYPE (TREE_OPERAND (fns, 0)) + == current_class_type, 20001120); + fns = TREE_OPERAND (fns, 1); + } + my_friendly_assert (TREE_CODE (fns) == IDENTIFIER_NODE + || TREE_CODE (fns) == LOOKUP_EXPR + || TREE_CODE (fns) == OVERLOAD, 20001120); + DECL_TEMPLATE_INFO (decl) = tree_cons (fns, args, NULL_TREE); if (has_default_arg) { - cp_error ("default arguments are not allowed in declaration of friend template specialization `%D'", + error ("default arguments are not allowed in declaration of friend template specialization `%D'", decl); return NULL_TREE; } if (inlinep) { - cp_error ("`inline' is not allowed in declaration of friend template specialization `%D'", + error ("`inline' is not allowed in declaration of friend template specialization `%D'", decl); return NULL_TREE; } @@ -8935,120 +9001,85 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, if (has_default_arg) add_defarg_fn (decl); - /* Plain overloading: will not be grok'd by grokclassfn. */ - if (! ctype && ! processing_template_decl - && DECL_LANGUAGE (decl) != lang_c - && (! DECL_USE_TEMPLATE (decl) || name_mangling_version < 1)) - set_mangled_name_for_decl (decl); - if (funcdef_flag) /* Make the init_value nonzero so pushdecl knows this is not tentative. error_mark_node is replaced later with the BLOCK. */ DECL_INITIAL (decl) = error_mark_node; + if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl)) + TREE_NOTHROW (decl) = 1; + /* Caller will do the rest of this. */ if (check < 0) return decl; - if (check && funcdef_flag) - DECL_INITIAL (decl) = error_mark_node; + if (flags == NO_SPECIAL && ctype && constructor_name (ctype) == declarator) + DECL_CONSTRUCTOR_P (decl) = 1; - if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) - { - tree tmp; - /* Just handle constructors here. We could do this - inside the following if stmt, but I think - that the code is more legible by breaking this - case out. See comments below for what each of - the following calls is supposed to do. */ - DECL_CONSTRUCTOR_P (decl) = 1; + /* Function gets the ugly name, field gets the nice one. This call + may change the type of the function (because of default + parameters)! */ + if (ctype != NULL_TREE) + grokclassfn (ctype, decl, flags, quals); - grokclassfn (ctype, decl, flags, quals); + decl = check_explicit_specialization (orig_declarator, decl, + template_count, + 2 * (funcdef_flag != 0) + + 4 * (friendp != 0)); + if (decl == error_mark_node) + return NULL_TREE; - decl = check_explicit_specialization (orig_declarator, decl, - template_count, - 2 * (funcdef_flag != 0) + - 4 * (friendp != 0)); + if (ctype != NULL_TREE + && (! TYPE_FOR_JAVA (ctype) || check_java_method (decl)) + && check) + { + tree old_decl; - if (decl == error_mark_node) - return NULL_TREE; + old_decl = check_classfn (ctype, decl); - maybe_vlist_ctor_wrapper (decl, funcdef_flag); + if (old_decl && TREE_CODE (old_decl) == TEMPLATE_DECL) + /* Because grokfndecl is always supposed to return a + FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT + here. We depend on our callers to figure out that its + really a template that's being returned. */ + old_decl = DECL_TEMPLATE_RESULT (old_decl); - if ((! TYPE_FOR_JAVA (ctype) || check_java_method (decl)) - && check) + if (old_decl && DECL_STATIC_FUNCTION_P (old_decl) + && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) { - tmp = check_classfn (ctype, decl); + /* Remove the `this' parm added by grokclassfn. + XXX Isn't this done in start_function, too? */ + revert_static_member_fn (decl); + last_function_parms = TREE_CHAIN (last_function_parms); + } + if (old_decl && DECL_ARTIFICIAL (old_decl)) + error ("definition of implicitly-declared `%D'", old_decl); - if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) - tmp = DECL_TEMPLATE_RESULT(tmp); + if (old_decl) + { + /* Since we've smashed OLD_DECL to its + DECL_TEMPLATE_RESULT, we must do the same to DECL. */ + if (TREE_CODE (decl) == TEMPLATE_DECL) + decl = DECL_TEMPLATE_RESULT (decl); - if (tmp && DECL_ARTIFICIAL (tmp)) - cp_error ("definition of implicitly-declared `%D'", tmp); - if (tmp && duplicate_decls (decl, tmp)) - return tmp; + /* Attempt to merge the declarations. This can fail, in + the case of some illegal specialization declarations. */ + if (!duplicate_decls (decl, old_decl)) + error ("no `%#D' member function declared in class `%T'", + decl, ctype); + return old_decl; } - if (! grok_ctor_properties (ctype, decl)) - return NULL_TREE; } - else - { - tree tmp; - - /* Function gets the ugly name, field gets the nice one. - This call may change the type of the function (because - of default parameters)! */ - if (ctype != NULL_TREE) - grokclassfn (ctype, decl, flags, quals); - - decl = check_explicit_specialization (orig_declarator, decl, - template_count, - 2 * (funcdef_flag != 0) + - 4 * (friendp != 0)); - if (decl == error_mark_node) - return NULL_TREE; - if (ctype != NULL_TREE - && (! TYPE_FOR_JAVA (ctype) || check_java_method (decl)) - && check) - { - tmp = check_classfn (ctype, decl); + if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl)) + return NULL_TREE; - if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) - tmp = DECL_TEMPLATE_RESULT (tmp); - - if (tmp && DECL_STATIC_FUNCTION_P (tmp) - && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) - { - /* Remove the `this' parm added by grokclassfn. - XXX Isn't this done in start_function, too? */ - revert_static_member_fn (&decl, NULL, NULL); - last_function_parms = TREE_CHAIN (last_function_parms); - } - if (tmp && DECL_ARTIFICIAL (tmp)) - cp_error ("definition of implicitly-declared `%D'", tmp); - if (tmp) - { - /* Attempt to merge the declarations. This can fail, in - the case of some illegal specialization declarations. */ - if (!duplicate_decls (decl, tmp)) - cp_error ("no `%#D' member function declared in class `%T'", - decl, ctype); - return tmp; - } - } + if (ctype == NULL_TREE || check) + return decl; - if (ctype == NULL_TREE || check) - return decl; + if (virtualp) + DECL_VIRTUAL_P (decl) = 1; - if (virtualp) - { - DECL_VIRTUAL_P (decl) = 1; - if (DECL_VINDEX (decl) == NULL_TREE) - DECL_VINDEX (decl) = error_mark_node; - IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; - } - } return decl; } @@ -9072,10 +9103,8 @@ grokvardecl (type, declarator, specbits_in, initialized, constp, in_namespace) can be initialized, the code will reach here. */ tree basetype = TYPE_OFFSET_BASETYPE (type); type = TREE_TYPE (type); - decl = build_lang_field_decl (VAR_DECL, declarator, type); + decl = build_lang_decl (VAR_DECL, declarator, type); DECL_CONTEXT (decl) = basetype; - DECL_CLASS_CONTEXT (decl) = basetype; - DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator); } else { @@ -9088,14 +9117,26 @@ grokvardecl (type, declarator, specbits_in, initialized, constp, in_namespace) else context = NULL_TREE; - decl = build_decl (VAR_DECL, declarator, complete_type (type)); + /* For namespace-scope variables, declared in a template, we + need the full lang_decl. The same is true for + namespace-scope variables that do not have C++ language + linkage. */ + if (context + && (processing_template_decl + || current_lang_name != lang_name_cplusplus)) + decl = build_lang_decl (VAR_DECL, declarator, type); + else + decl = build_decl (VAR_DECL, declarator, type); if (context) set_decl_namespace (decl, context, 0); context = DECL_CONTEXT (decl); if (declarator && context && current_lang_name != lang_name_c) - DECL_ASSEMBLER_NAME (decl) = build_static_name (context, declarator); + /* We can't mangle lazily here because we don't have any + way to recover whether or not a variable was `extern + "C"' later. */ + mangle_decl (decl); } if (in_namespace) @@ -9140,10 +9181,10 @@ grokvardecl (type, declarator, specbits_in, initialized, constp, in_namespace) tree t = no_linkage_check (TREE_TYPE (decl)); if (t) { - if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) + if (TYPE_ANONYMOUS_P (t)) /* Ignore for now; `enum { foo } e' is pretty common. */; else - cp_pedwarn ("non-local variable `%#D' uses local type `%T'", + pedwarn ("non-local variable `%#D' uses local type `%T'", decl, t); } } @@ -9160,7 +9201,10 @@ build_ptrmemfunc_type (type) { tree fields[4]; tree t; - tree u; + tree unqualified_variant = NULL_TREE; + + if (type == error_mark_node) + return type; /* If a canonical type already exists for this type, use it. We use this method instead of type_hash_canon, because it only does a @@ -9169,40 +9213,46 @@ build_ptrmemfunc_type (type) if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type))) return t; - push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); - - u = make_lang_type (UNION_TYPE); - SET_IS_AGGR_TYPE (u, 0); - fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type); - fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, - delta_type_node); - finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node); - TYPE_NAME (u) = NULL_TREE; - - t = make_lang_type (RECORD_TYPE); + /* Make sure that we always have the unqualified pointer-to-member + type first. */ + if (cp_type_quals (type) != TYPE_UNQUALIFIED) + unqualified_variant + = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type)); + t = make_aggr_type (RECORD_TYPE); /* Let the front-end know this is a pointer to member function... */ TYPE_PTRMEMFUNC_FLAG (t) = 1; /* ... and not really an aggregate. */ SET_IS_AGGR_TYPE (t, 0); - fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, - delta_type_node); - fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, - delta_type_node); - fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u); - finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node); - - pop_obstacks (); + fields[0] = build_decl (FIELD_DECL, pfn_identifier, type); + fields[1] = build_decl (FIELD_DECL, delta_identifier, + delta_type_node); + finish_builtin_type (t, "__ptrmemfunc_type", fields, 1, ptr_type_node); /* Zap out the name so that the back-end will give us the debugging information for this anonymous RECORD_TYPE. */ TYPE_NAME (t) = NULL_TREE; + /* If this is not the unqualified form of this pointer-to-member + type, set the TYPE_MAIN_VARIANT for this type to be the + unqualified type. Since they are actually RECORD_TYPEs that are + not variants of each other, we must do this manually. */ + if (cp_type_quals (type) != TYPE_UNQUALIFIED) + { + t = build_qualified_type (t, cp_type_quals (type)); + TYPE_MAIN_VARIANT (t) = unqualified_variant; + TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (unqualified_variant); + TYPE_NEXT_VARIANT (unqualified_variant) = t; + } + + /* Cache this pointer-to-member type so that we can find it again + later. */ TYPE_SET_PTRMEMFUNC_TYPE (type, t); /* Seems to be wanted. */ CLASSTYPE_GOT_SEMICOLON (t) = 1; + return t; } @@ -9224,7 +9274,7 @@ check_static_variable_definition (decl, type) required. */ if (CLASS_TYPE_P (type) || TREE_CODE (type) == REFERENCE_TYPE) { - cp_error ("in-class initialization of static data member of non-integral type `%T'", + error ("invalid in-class initialization of static data member of non-integral type `%T'", type); /* If we just return the declaration, crashes will sometimes occur. We therefore return void_type_node, as if this was a @@ -9233,14 +9283,268 @@ check_static_variable_definition (decl, type) return 1; } else if (!CP_TYPE_CONST_P (type)) - cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'", + error ("ISO C++ forbids in-class initialization of non-const static member `%D'", decl); else if (pedantic && !INTEGRAL_TYPE_P (type)) - cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", decl, type); + pedwarn ("ISO C++ forbids initialization of member constant `%D' of non-integral type `%T'", decl, type); return 0; } +/* Given the SIZE (i.e., number of elements) in an array, compute an + appropriate index type for the array. If non-NULL, NAME is the + name of the thing being declared. */ + +tree +compute_array_index_type (name, size) + tree name; + tree size; +{ + tree itype; + + /* If this involves a template parameter, it will be a constant at + instantiation time, but we don't know what the value is yet. + Even if no template parameters are involved, we may an expression + that is not a constant; we don't even simplify `1 + 2' when + processing a template. */ + if (processing_template_decl) + { + /* Resolve a qualified reference to an enumerator or static + const data member of ours. */ + if (TREE_CODE (size) == SCOPE_REF + && TREE_OPERAND (size, 0) == current_class_type) + { + tree t = lookup_field (current_class_type, + TREE_OPERAND (size, 1), 0, 0); + if (t) + size = t; + } + + return build_index_type (build_min (MINUS_EXPR, sizetype, + size, integer_one_node)); + } + + /* The size might be the result of a cast. */ + STRIP_TYPE_NOPS (size); + + /* It might be a const variable or enumeration constant. */ + size = decl_constant_value (size); + + /* The array bound must be an integer type. */ + if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE + && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE + && TREE_CODE (TREE_TYPE (size)) != BOOLEAN_TYPE) + { + if (name) + error ("size of array `%D' has non-integer type", name); + else + error ("size of array has non-integer type"); + size = integer_one_node; + } + + /* Normally, the array-bound will be a constant. */ + if (TREE_CODE (size) == INTEGER_CST) + { + /* Check to see if the array bound overflowed. Make that an + error, no matter how generous we're being. */ + int old_flag_pedantic_errors = flag_pedantic_errors; + int old_pedantic = pedantic; + pedantic = flag_pedantic_errors = 1; + constant_expression_warning (size); + pedantic = old_pedantic; + flag_pedantic_errors = old_flag_pedantic_errors; + + /* An array must have a positive number of elements. */ + if (INT_CST_LT (size, integer_zero_node)) + { + if (name) + error ("size of array `%D' is negative", name); + else + error ("size of array is negative"); + size = integer_one_node; + } + /* Except that an extension we allow zero-sized arrays. We + always allow them in system headers because glibc uses + them. */ + else if (integer_zerop (size) && pedantic && !in_system_header) + { + if (name) + pedwarn ("ISO C++ forbids zero-size array `%D'", name); + else + pedwarn ("ISO C++ forbids zero-size array"); + } + } + else if (TREE_CONSTANT (size)) + { + /* `(int) &fn' is not a valid array bound. */ + if (name) + error ("size of array `%D' is not an integral constant-expression", + name); + else + error ("size of array is not an integral constant-expression"); + } + + /* Compute the index of the largest element in the array. It is + one less than the number of elements in the array. */ + itype + = fold (cp_build_binary_op (MINUS_EXPR, + cp_convert (ssizetype, size), + cp_convert (ssizetype, + integer_one_node))); + + /* Check for variable-sized arrays. We allow such things as an + extension, even though they are not allowed in ANSI/ISO C++. */ + if (!TREE_CONSTANT (itype)) + { + if (pedantic) + { + if (name) + pedwarn ("ISO C++ forbids variable-size array `%D'", + name); + else + pedwarn ("ISO C++ forbids variable-size array"); + } + + /* Create a variable-sized array index type. */ + itype = variable_size (itype); + } + /* Make sure that there was no overflow when creating to a signed + index type. (For example, on a 32-bit machine, an array with + size 2^32 - 1 is too big.) */ + else if (TREE_OVERFLOW (itype)) + { + error ("overflow in array dimension"); + TREE_OVERFLOW (itype) = 0; + } + + /* Create and return the appropriate index type. */ + return build_index_type (itype); +} + +/* Returns an ARRAY_TYPE for an array with SIZE elements of the + indicated TYPE. If non-NULL, NAME is the NAME of the declaration + with this type. */ + +static tree +create_array_type_for_decl (name, type, size) + tree name; + tree type; + tree size; +{ + tree itype = NULL_TREE; + const char* error_msg; + + /* If things have already gone awry, bail now. */ + if (type == error_mark_node || size == error_mark_node) + return error_mark_node; + + /* Assume that everything will go OK. */ + error_msg = NULL; + + /* There are some types which cannot be array elements. */ + switch (TREE_CODE (type)) + { + case VOID_TYPE: + error_msg = "array of void"; + break; + + case FUNCTION_TYPE: + error_msg = "array of functions"; + break; + + case REFERENCE_TYPE: + error_msg = "array of references"; + break; + + case OFFSET_TYPE: + error_msg = "array of data members"; + break; + + case METHOD_TYPE: + error_msg = "array of function members"; + break; + + default: + break; + } + + /* If something went wrong, issue an error-message and return. */ + if (error_msg) + { + if (name) + error ("declaration of `%D' as %s", name, error_msg); + else + error ("creating %s", error_msg); + + return error_mark_node; + } + + /* [dcl.array] + + The constant expressions that specify the bounds of the arrays + can be omitted only for the first member of the sequence. */ + if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)) + { + if (name) + error ("declaration of `%D' as multidimensional array must have bounds for all dimensions except the first", + name); + else + error ("multidimensional array must have bounds for all dimensions except the first"); + + return error_mark_node; + } + + /* Figure out the index type for the array. */ + if (size) + itype = compute_array_index_type (name, size); + + return build_cplus_array_type (type, itype); +} + +/* Check that it's OK to declare a function with the indicated TYPE. + SFK indicates the kind of special function (if any) that this + function is. OPTYPE is the type given in a conversion operator + declaration. Returns the actual return type of the function; that + may be different than TYPE if an error occurs, or for certain + special functions. */ + +static tree +check_special_function_return_type (sfk, type, optype) + special_function_kind sfk; + tree type; + tree optype; +{ + switch (sfk) + { + case sfk_constructor: + if (type) + error ("return type specification for constructor invalid"); + + type = void_type_node; + break; + + case sfk_destructor: + if (type) + error ("return type specification for destructor invalid"); + type = void_type_node; + break; + + case sfk_conversion: + if (type && !same_type_p (type, optype)) + error ("operator `%T' declared to return `%T'", optype, type); + else if (type) + pedwarn ("return type specified for `operator %T'", optype); + type = optype; + break; + + default: + abort (); + break; + } + + return type; +} + /* Given declspecs and a declarator, determine the name and type of the object declared and construct a ..._DECL node for it. @@ -9268,10 +9572,11 @@ check_static_variable_definition (decl, type) BITFIELD for a field with specified width. INITIALIZED is 1 if the decl has an initializer. - ATTRLIST is a TREE_LIST node with prefix attributes in TREE_VALUE and - normal attributes in TREE_PURPOSE, or NULL_TREE. + ATTRLIST is a pointer to the list of attributes, which may be NULL + if there are none; *ATTRLIST may be modified if attributes from inside + the declarator should be applied to the declaration. - In the TYPENAME case, DECLARATOR is really an absolute declarator. + In the TYPENAME case, DECLARATOR is really an abstract declarator. It may also be so in the PARM case, for a prototype where the argument type is specified but not the name. @@ -9295,20 +9600,19 @@ check_static_variable_definition (decl, type) is erroneous, NULL_TREE is returned. QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member - function, these are the qualifiers to give to the `this' pointer. + function, these are the qualifiers to give to the `this' pointer. We + apply TYPE_QUAL_RESTRICT to the this ptr, not the object. May return void_type_node if the declarator turned out to be a friend. See grokfield for details. */ -enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; - tree grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) tree declspecs; tree declarator; enum decl_context decl_context; int initialized; - tree attrlist; + tree *attrlist; { RID_BIT_TYPE specbits; int nclasses = 0; @@ -9323,16 +9627,17 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) int explicit_int = 0; int explicit_char = 0; int defaulted_int = 0; - int opaque_typedef = 0; + int extern_langp = 0; + tree typedef_decl = NULL_TREE; - char *name; + const char *name; tree typedef_type = NULL_TREE; int funcdef_flag = 0; enum tree_code innermost_code = ERROR_MARK; int bitfield = 0; #if 0 /* See the code below that used this. */ - tree decl_machine_attr = NULL_TREE; + tree decl_attr = NULL_TREE; #endif /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ @@ -9341,7 +9646,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* Keep track of what sort of function is being processed so that we can warn about default return values, or explicit return values which do not match prescribed defaults. */ - enum return_types return_type = return_normal; + special_function_kind sfk = sfk_none; tree dname = NULL_TREE; tree ctype = current_class_type; @@ -9351,8 +9656,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) tree raises = NULL_TREE; int template_count = 0; tree in_namespace = NULL_TREE; - tree inner_attrs; - int ignore_attrs; + tree returned_attrs = NULL_TREE; RIDBIT_RESET_ALL (specbits); if (decl_context == FUNCDEF) @@ -9391,7 +9695,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) my_friendly_assert (flags == NO_SPECIAL, 152); flags = DTOR_FLAG; - return_type = return_dtor; + sfk = sfk_destructor; if (TREE_CODE (name) == TYPE_DECL) TREE_OPERAND (decl, 0) = name = constructor_name (name); my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); @@ -9418,7 +9722,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (rename) { - cp_error ("destructor `%T' must match class name `%T'", + error ("destructor `%T' must match class name `%T'", name, rename); TREE_OPERAND (decl, 0) = rename; } @@ -9436,31 +9740,30 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) break; case CALL_EXPR: - if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) + if (parmlist_is_exprlist (CALL_DECLARATOR_PARMS (decl))) { /* This is actually a variable declaration using constructor syntax. We need to call start_decl and cp_finish_decl so we can get the variable initialized... */ - tree attributes, prefix_attributes; + tree attributes; *next = TREE_OPERAND (decl, 0); - init = TREE_OPERAND (decl, 1); + init = CALL_DECLARATOR_PARMS (decl); if (attrlist) { - attributes = TREE_PURPOSE (attrlist); - prefix_attributes = TREE_VALUE (attrlist); + attributes = *attrlist; } else { attributes = NULL_TREE; - prefix_attributes = NULL_TREE; } decl = start_decl (declarator, declspecs, 1, - attributes, prefix_attributes); + attributes, NULL_TREE); + decl_type_access_control (decl); if (decl) { /* Look for __unused__ attribute */ @@ -9469,7 +9772,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) finish_decl (decl, init, NULL_TREE); } else - cp_error ("invalid declarator"); + error ("invalid declarator"); return 0; } innermost_code = TREE_CODE (decl); @@ -9489,12 +9792,12 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) && decl != NULL_TREE && flags != DTOR_FLAG && decl == constructor_name (ctype)) { - return_type = return_ctor; + sfk = sfk_constructor; ctor_return_type = ctype; } ctype = NULL_TREE; break; - + case TEMPLATE_ID_EXPR: { tree fns = TREE_OPERAND (decl, 0); @@ -9520,26 +9823,26 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) next = 0; - if (is_rid (dname)) + if (C_IS_RESERVED_WORD (dname)) { - cp_error ("declarator-id missing; using reserved word `%D'", + error ("declarator-id missing; using reserved word `%D'", dname); name = IDENTIFIER_POINTER (dname); } - if (! IDENTIFIER_OPNAME_P (dname) - /* GNU/Linux headers use '__op'. Arrgh. */ - || (IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))) + else if (!IDENTIFIER_TYPENAME_P (dname)) name = IDENTIFIER_POINTER (dname); else { - if (IDENTIFIER_TYPENAME_P (dname)) - { - my_friendly_assert (flags == NO_SPECIAL, 154); - flags = TYPENAME_FLAG; - ctor_return_type = TREE_TYPE (dname); - return_type = return_conversion; - } - name = operator_name_string (dname); + my_friendly_assert (flags == NO_SPECIAL, 154); + flags = TYPENAME_FLAG; + ctor_return_type = TREE_TYPE (dname); + sfk = sfk_conversion; + if (IDENTIFIER_GLOBAL_VALUE (dname) + && (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (dname)) + == TYPE_DECL)) + name = IDENTIFIER_POINTER (dname); + else + name = "<invalid operator>"; } break; @@ -9564,11 +9867,11 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) ctype = cname; else if (TREE_CODE (cname) == TEMPLATE_TYPE_PARM - || TREE_CODE (cname) == TEMPLATE_TEMPLATE_PARM) + || TREE_CODE (cname) == BOUND_TEMPLATE_TEMPLATE_PARM) { - cp_error ("`%T::%D' is not a valid declarator", cname, + error ("`%T::%D' is not a valid declarator", cname, TREE_OPERAND (decl, 1)); - cp_error (" perhaps you want `typename %T::%D' to make it a type", + error (" perhaps you want `typename %T::%D' to make it a type", cname, TREE_OPERAND (decl, 1)); return void_type_node; } @@ -9580,7 +9883,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) { if (! UNIQUELY_DERIVED_FROM_P (cname, ctype)) { - cp_error ("type `%T' is not derived from type `%T'", + error ("type `%T' is not derived from type `%T'", cname, ctype); TREE_OPERAND (decl, 0) = NULL_TREE; } @@ -9601,7 +9904,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (TREE_CODE (decl) == IDENTIFIER_NODE && constructor_name (ctype) == decl) { - return_type = return_ctor; + sfk = sfk_constructor; ctor_return_type = ctype; } else if (TREE_CODE (decl) == BIT_NOT_EXPR @@ -9609,7 +9912,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) && (constructor_name (ctype) == TREE_OPERAND (decl, 0) || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) { - return_type = return_dtor; + sfk = sfk_destructor; ctor_return_type = ctype; flags = DTOR_FLAG; TREE_OPERAND (decl, 0) = constructor_name (ctype); @@ -9626,9 +9929,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) case TYPE_DECL: /* Parse error puts this typespec where a declarator should go. */ - cp_error ("`%T' specified as declarator-id", DECL_NAME (decl)); + error ("`%T' specified as declarator-id", DECL_NAME (decl)); if (TREE_TYPE (decl) == current_class_type) - cp_error (" perhaps you want `%T' for a constructor", + error (" perhaps you want `%T' for a constructor", current_class_name); dname = DECL_NAME (decl); name = IDENTIFIER_POINTER (dname); @@ -9636,19 +9939,15 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* Avoid giving two errors for this. */ IDENTIFIER_CLASS_VALUE (dname) = NULL_TREE; - declspecs = temp_tree_cons (NULL_TREE, integer_type_node, - declspecs); + declspecs = tree_cons (NULL_TREE, integer_type_node, declspecs); *next = dname; next = 0; break; default: - cp_compiler_error ("`%D' as declarator", decl); - return 0; /* We used to do a 155 abort here. */ + internal_error ("`%D' as declarator", decl); } } - if (name == NULL) - name = "type name"; } /* A function definition's declarator must have the form of @@ -9661,7 +9960,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) && innermost_code != CALL_EXPR && ! (ctype && declspecs == NULL_TREE)) { - cp_error ("declaration of `%D' as non-function", dname); + error ("declaration of `%D' as non-function", dname); return void_type_node; } @@ -9679,8 +9978,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) We also want to avoid calling this a PARM if it is in a namespace. */ - if (decl_context == NORMAL && ! namespace_bindings_p () - && ! pseudo_global_level_p ()) + if (decl_context == NORMAL && !toplevel_bindings_p ()) { struct binding_level *b = current_binding_level; current_binding_level = b->level_chain; @@ -9689,6 +9987,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) current_binding_level = b; } + if (name == NULL) + name = decl_context == PARM ? "parameter" : "type name"; + /* Look through the decl specs and record which ones appear. Some typespecs are defined as built-in typenames. Others, the ones that are modifiers of other types, @@ -9718,6 +10019,14 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) id = TREE_VALUE (spec); + /* If the entire declaration is itself tagged as deprecated then + suppress reports of deprecated items. */ + if (!adding_implicit_members && id && TREE_DEPRECATED (id)) + { + if (deprecated_state != DEPRECATED_SUPPRESS) + warn_deprecated_use (id); + } + if (TREE_CODE (id) == IDENTIFIER_NODE) { if (id == ridpointers[(int) RID_INT] @@ -9730,7 +10039,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (id == ridpointers[(int) RID_BOOL]) error ("`bool' is now a keyword"); else - cp_error ("extraneous `%T' ignored", id); + error ("extraneous `%T' ignored", id); } else { @@ -9746,7 +10055,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (IDENTIFIER_HAS_TYPE_VALUE (id)) { if (type) - cp_error ("multiple declarations `%T' and `%T'", type, id); + error ("multiple declarations `%T' and `%T'", type, id); else type = IDENTIFIER_TYPE_VALUE (id); goto found; @@ -9759,7 +10068,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) { if (pedantic && ! in_system_header && warn_long_long) - pedwarn ("ANSI C++ does not support `long long'"); + pedwarn ("ISO C++ does not support `long long'"); if (longlong) error ("`long long long' is too long for GCC"); else @@ -9767,16 +10076,20 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) } else if (RIDBIT_SETP (i, specbits)) pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); + if (i == (int)RID_EXTERN + && TREE_PURPOSE (spec) == error_mark_node) + /* This extern was part of a language linkage. */ + extern_langp = 1; RIDBIT_SET (i, specbits); goto found; } } } /* C++ aggregate types. */ - else if (TREE_CODE (id) == TYPE_DECL || TREE_CODE (id) == TEMPLATE_DECL) + else if (TREE_CODE (id) == TYPE_DECL) { if (type) - cp_error ("multiple declarations `%T' and `%T'", type, + error ("multiple declarations `%T' and `%T'", type, TREE_TYPE (id)); else { @@ -9798,7 +10111,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) type = TREE_TYPE (t); #if 0 /* See the code below that used this. */ - decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); + decl_attr = DECL_ATTRIBUTES (id); #endif typedef_decl = t; } @@ -9813,10 +10126,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) typedef_type = type; /* No type at all: default to `int', and set DEFAULTED_INT - because it was not a user-defined typedef. - Except when we have a `typedef' inside a signature, in - which case the type defaults to `unknown type' and is - instantiated when assigning to a signature pointer or ref. */ + because it was not a user-defined typedef. */ if (type == NULL_TREE && (RIDBIT_SETP (RID_SIGNED, specbits) @@ -9829,67 +10139,49 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) defaulted_int = 1; } - if (type == NULL_TREE) + if (sfk != sfk_none) + type = check_special_function_return_type (sfk, type, + ctor_return_type); + else if (type == NULL_TREE) { + int is_main; + explicit_int = -1; - if (return_type == return_dtor) - type = void_type_node; - else if (return_type == return_ctor) - type = build_pointer_type (ctor_return_type); - else if (return_type == return_conversion) - type = ctor_return_type; - else if (current_class_type - && IS_SIGNATURE (current_class_type) - && RIDBIT_SETP (RID_TYPEDEF, specbits) - && (decl_context == FIELD || decl_context == NORMAL)) - { - explicit_int = 0; - opaque_typedef = 1; - type = copy_node (opaque_type_node); - } - else - { - /* We handle `main' specially here, because 'main () { }' is so - common. With no options, it is allowed. With -Wreturn-type, - it is a warning. It is only an error with -pedantic-errors. */ - int is_main = (funcdef_flag - && MAIN_NAME_P (dname) - && ctype == NULL_TREE - && in_namespace == NULL_TREE - && current_namespace == global_namespace); - if (in_system_header) - /* Allow it, sigh. */; - else if (pedantic || ! is_main) - cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type", - dname); - else if (warn_return_type) - cp_warning ("ANSI C++ forbids declaration `%D' with no type", - dname); + /* We handle `main' specially here, because 'main () { }' is so + common. With no options, it is allowed. With -Wreturn-type, + it is a warning. It is only an error with -pedantic-errors. */ + is_main = (funcdef_flag + && dname && MAIN_NAME_P (dname) + && ctype == NULL_TREE + && in_namespace == NULL_TREE + && current_namespace == global_namespace); + + if (in_system_header || flag_ms_extensions) + /* Allow it, sigh. */; + else if (pedantic || ! is_main) + pedwarn ("ISO C++ forbids declaration of `%s' with no type", + name); + else if (warn_return_type) + warning ("ISO C++ forbids declaration of `%s' with no type", + name); - type = integer_type_node; - } - } - else if (return_type == return_dtor) - { - error ("return type specification for destructor invalid"); - type = void_type_node; - } - else if (return_type == return_ctor) - { - error ("return type specification for constructor invalid"); - type = build_pointer_type (ctor_return_type); + type = integer_type_node; } - else if (return_type == return_conversion) + + if (type && TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type)) { - if (!same_type_p (type, ctor_return_type)) - cp_error ("operator `%T' declared to return `%T'", - ctor_return_type, type); - else - cp_pedwarn ("return type specified for `operator %T'", - ctor_return_type); + /* The implicit typename extension is deprecated and will be + removed. Warn about its use now. */ + warning ("`%T' is implicitly a typename", type); + cp_deprecated ("implicit typename"); - type = ctor_return_type; + /* Now remove its implicitness, so that we don't warn again. + For instance this might be a typedef, and we do not want to + warn on uses of the typedef itself. Simply clearing the + TREE_TYPE is insufficient. */ + type = copy_node (type); + TREE_TYPE (type) = NULL_TREE; } ctype = NULL_TREE; @@ -9903,8 +10195,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) && TYPE_MAIN_VARIANT (type) == double_type_node) { RIDBIT_RESET (RID_LONG, specbits); - type = build_qualified_type (long_double_type_node, - CP_TYPE_QUALS (type)); + type = build_qualified_type (long_double_type_node, + cp_type_quals (type)); } /* Check all other uses of type modifiers. */ @@ -9967,14 +10259,24 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* Decide whether an integer type is signed or not. Optionally treat bitfields as signed by default. */ if (RIDBIT_SETP (RID_UNSIGNED, specbits) - || (bitfield && ! flag_signed_bitfields - && (explicit_int || defaulted_int || explicit_char - /* A typedef for plain `int' without `signed' - can be controlled just like plain `int'. */ - || ! (typedef_decl != NULL_TREE - && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) - && TREE_CODE (type) != ENUMERAL_TYPE - && RIDBIT_NOTSETP (RID_SIGNED, specbits))) + /* [class.bit] + + It is implementation-defined whether a plain (neither + explicitly signed or unsigned) char, short, int, or long + bit-field is signed or unsigned. + + Naturally, we extend this to long long as well. Note that + this does not include wchar_t. */ + || (bitfield && !flag_signed_bitfields + && RIDBIT_NOTSETP (RID_SIGNED, specbits) + /* A typedef for plain `int' without `signed' can be + controlled just like plain `int', but a typedef for + `signed int' cannot be so controlled. */ + && !(typedef_decl + && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)) + && (TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == CHAR_TYPE) + && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node))) { if (longlong) type = long_long_unsigned_type_node; @@ -10024,11 +10326,11 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) type = build_complex_type (type); } - if (return_type == return_conversion + if (sfk == sfk_conversion && (RIDBIT_SETP (RID_CONST, specbits) || RIDBIT_SETP (RID_VOLATILE, specbits) || RIDBIT_SETP (RID_RESTRICT, specbits))) - cp_error ("qualifiers are not allowed on declaration of `operator %T'", + error ("qualifiers are not allowed on declaration of `operator %T'", ctor_return_type); /* Set CONSTP if this declaration is `const', whether by @@ -10036,9 +10338,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) Likewise for VOLATILEP. */ constp = !! RIDBIT_SETP (RID_CONST, specbits) + CP_TYPE_CONST_P (type); - restrictp = + restrictp = !! RIDBIT_SETP (RID_RESTRICT, specbits) + CP_TYPE_RESTRICT_P (type); - volatilep = + volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + CP_TYPE_VOLATILE_P (type); type_quals = ((constp ? TYPE_QUAL_CONST : 0) | (restrictp ? TYPE_QUAL_RESTRICT : 0) @@ -10056,37 +10358,19 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (virtualp && staticp == 2) { - cp_error ("member `%D' cannot be declared both virtual and static", + error ("member `%D' cannot be declared both virtual and static", dname); staticp = 0; } friendp = RIDBIT_SETP (RID_FRIEND, specbits); RIDBIT_RESET (RID_FRIEND, specbits); - /* $7.1.2, Function specifiers */ - if (friendp && explicitp) - error ("only declarations of constructors can be `explicit'"); - - if (RIDBIT_SETP (RID_MUTABLE, specbits)) - { - if (decl_context == PARM) - { - error ("non-member `%s' cannot be declared `mutable'", name); - RIDBIT_RESET (RID_MUTABLE, specbits); - } - else if (friendp || decl_context == TYPENAME) - { - error ("non-object member `%s' cannot be declared `mutable'", name); - RIDBIT_RESET (RID_MUTABLE, specbits); - } - } - /* Warn if two storage classes are given. Default to `auto'. */ if (RIDBIT_ANY_SET (specbits)) { if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++; - if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++; + if (RIDBIT_SETP (RID_EXTERN, specbits) && !extern_langp) nclasses++; if (decl_context == PARM && nclasses > 0) error ("storage class specifiers invalid in parameter declarations"); if (RIDBIT_SETP (RID_TYPEDEF, specbits)) @@ -10097,6 +10381,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) } if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++; if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++; + if (!nclasses && !friendp && extern_langp) + nclasses++; } /* Give error if `virtual' is used outside of class declaration. */ @@ -10106,49 +10392,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) error ("virtual outside class declaration"); virtualp = 0; } - if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits)) - { - error ("only members can be declared mutable"); - RIDBIT_RESET (RID_MUTABLE, specbits); - } /* Static anonymous unions are dealt with here. */ if (staticp && decl_context == TYPENAME && TREE_CODE (declspecs) == TREE_LIST - && ANON_UNION_TYPE_P (TREE_VALUE (declspecs))) + && ANON_AGGR_TYPE_P (TREE_VALUE (declspecs))) decl_context = FIELD; - /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual' - is used in a signature member function declaration. */ - if (decl_context == FIELD - && IS_SIGNATURE (current_class_type) - && RIDBIT_NOTSETP (RID_TYPEDEF, specbits)) - { - if (type_quals != TYPE_UNQUALIFIED) - { - error ("type qualifiers specified for signature member function `%s'", name); - type_quals = TYPE_UNQUALIFIED; - } - if (inlinep) - { - error ("`inline' specified for signature member function `%s'", name); - /* Later, we'll make signature member functions inline. */ - inlinep = 0; - } - if (friendp) - { - error ("`friend' declaration in signature definition"); - friendp = 0; - } - if (virtualp) - { - error ("`virtual' specified for signature member function `%s'", - name); - /* Later, we'll make signature member functions virtual. */ - virtualp = 0; - } - } - /* Warn about storage classes that are invalid for certain kinds of declarations (parameters, typenames, etc.). */ @@ -10163,11 +10413,10 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) ; else if (decl_context == FIELD - && ! IS_SIGNATURE (current_class_type) - /* C++ allows static class elements */ - && RIDBIT_SETP (RID_STATIC, specbits)) - /* C++ also allows inlines and signed and unsigned elements, - but in those cases we don't come in here. */ + /* C++ allows static class elements */ + && RIDBIT_SETP (RID_STATIC, specbits)) + /* C++ also allows inlines and signed and unsigned elements, + but in those cases we don't come in here. */ ; else { @@ -10178,34 +10427,36 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (declarator) { - /* Avoid trying to get an operand off an identifier node. */ + /* Avoid trying to get an operand off an identifier node. */ if (TREE_CODE (declarator) == IDENTIFIER_NODE) tmp = declarator; else tmp = TREE_OPERAND (declarator, 0); op = IDENTIFIER_OPNAME_P (tmp); + if (IDENTIFIER_TYPENAME_P (tmp)) + { + if (IDENTIFIER_GLOBAL_VALUE (tmp) + && (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (tmp)) + == TYPE_DECL)) + name = IDENTIFIER_POINTER (tmp); + else + name = "<invalid operator>"; + } } error ("storage class specified for %s `%s'", - IS_SIGNATURE (current_class_type) - ? (op - ? "signature member operator" - : "signature member function") - : (op ? "member operator" : "field"), - op ? operator_name_string (tmp) : name); + op ? "member operator" : "field", + name); } else - error (((decl_context == PARM || decl_context == CATCHPARM) - ? "storage class specified for parameter `%s'" - : "storage class specified for typename"), name); + { + if (decl_context == PARM || decl_context == CATCHPARM) + error ("storage class specified for parameter `%s'", name); + else + error ("storage class specified for typename"); + } RIDBIT_RESET (RID_REGISTER, specbits); RIDBIT_RESET (RID_AUTO, specbits); RIDBIT_RESET (RID_EXTERN, specbits); - - if (decl_context == FIELD && IS_SIGNATURE (current_class_type)) - { - RIDBIT_RESET (RID_STATIC, specbits); - staticp = 0; - } } } else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag) @@ -10236,9 +10487,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) Descend through it, creating more complex types, until we reach the declared identifier (or NULL_TREE, in an absolute declarator). */ - inner_attrs = NULL_TREE; - ignore_attrs = 0; - while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE && TREE_CODE (declarator) != TEMPLATE_ID_EXPR) { @@ -10280,220 +10528,70 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (ctype != NULL_TREE) { tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); - ctype = grok_method_quals (ctype, dummy, quals); + grok_method_quals (ctype, dummy, quals); type = TREE_TYPE (dummy); + ctype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))); quals = NULL_TREE; } } - /* See the comment for the TREE_LIST case, below. */ - if (ignore_attrs) - ignore_attrs = 0; - else if (inner_attrs) - { - decl_attributes (type, inner_attrs, NULL_TREE); - inner_attrs = NULL_TREE; - } - switch (TREE_CODE (declarator)) { case TREE_LIST: { /* We encode a declarator with embedded attributes using - a TREE_LIST. The attributes apply to the declarator - directly inside them, so we have to skip an iteration - before applying them to the type. If the declarator just - inside is the declarator-id, we apply the attrs to the - decl itself. */ - inner_attrs = TREE_PURPOSE (declarator); - ignore_attrs = 1; + a TREE_LIST. */ + tree attrs = TREE_PURPOSE (declarator); + tree inner_decl; + int attr_flags; + declarator = TREE_VALUE (declarator); + inner_decl = declarator; + while (inner_decl != NULL_TREE + && TREE_CODE (inner_decl) == TREE_LIST) + inner_decl = TREE_VALUE (inner_decl); + attr_flags = 0; + if (inner_decl == NULL_TREE + || TREE_CODE (inner_decl) == IDENTIFIER_NODE) + attr_flags |= (int) ATTR_FLAG_DECL_NEXT; + if (TREE_CODE (inner_decl) == CALL_EXPR) + attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT; + if (TREE_CODE (inner_decl) == ARRAY_REF) + attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT; + returned_attrs = decl_attributes (&type, + chainon (returned_attrs, attrs), + attr_flags); } break; case ARRAY_REF: { - register tree itype = NULL_TREE; - register tree size = TREE_OPERAND (declarator, 1); - /* The index is a signed object `sizetype' bits wide. */ - tree index_type = signed_type (sizetype); - - declarator = TREE_OPERAND (declarator, 0); + register tree size; - /* Check for some types that there cannot be arrays of. */ - - if (TREE_CODE (type) == VOID_TYPE) - { - cp_error ("declaration of `%D' as array of voids", dname); - type = error_mark_node; - } - - if (TREE_CODE (type) == FUNCTION_TYPE) - { - cp_error ("declaration of `%D' as array of functions", dname); - type = error_mark_node; - } - - /* ARM $8.4.3: Since you can't have a pointer to a reference, - you can't have arrays of references. If we allowed them, - then we'd be saying x[i] is valid for an array x, but - then you'd have to ask: what does `*(x + i)' mean? */ - if (TREE_CODE (type) == REFERENCE_TYPE) - { - if (decl_context == TYPENAME) - cp_error ("cannot make arrays of references"); - else - cp_error ("declaration of `%D' as array of references", - dname); - type = error_mark_node; - } - - if (TREE_CODE (type) == OFFSET_TYPE) - { - cp_error ("declaration of `%D' as array of data members", - dname); - type = error_mark_node; - } - - if (TREE_CODE (type) == METHOD_TYPE) - { - cp_error ("declaration of `%D' as array of function members", - dname); - type = error_mark_node; - } - - if (size == error_mark_node) - type = error_mark_node; - else if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)) - { - /* [dcl.array] - - the constant expressions that specify the bounds of - the arrays can be omitted only for the first member - of the sequence. */ - cp_error ("declaration of `%D' as multidimensional array", - dname); - cp_error ("must have bounds for all dimensions except the first"); - type = error_mark_node; - } - - if (type == error_mark_node) - continue; + size = TREE_OPERAND (declarator, 1); /* VC++ spells a zero-sized array with []. */ if (size == NULL_TREE && decl_context == FIELD && ! staticp && ! RIDBIT_SETP (RID_TYPEDEF, specbits)) size = integer_zero_node; - if (size) - { - /* Must suspend_momentary here because the index - type may need to live until the end of the function. - For example, it is used in the declaration of a - variable which requires destructing at the end of - the function; then build_vec_delete will need this - value. */ - int yes = suspend_momentary (); - /* Might be a cast. */ - if (TREE_CODE (size) == NOP_EXPR - && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) - size = TREE_OPERAND (size, 0); - - /* If this involves a template parameter, it will be a - constant at instantiation time, but we don't know - what the value is yet. Even if no template - parameters are involved, we may an expression that - is not a constant; we don't even simplify `1 + 2' - when processing a template. */ - if (processing_template_decl) - { - /* Resolve a qualified reference to an enumerator or - static const data member of ours. */ - if (TREE_CODE (size) == SCOPE_REF - && TREE_OPERAND (size, 0) == current_class_type) - { - tree t = lookup_field (current_class_type, - TREE_OPERAND (size, 1), 0, 0); - if (t) - size = t; - } - - itype = build_index_type (build_min - (MINUS_EXPR, sizetype, size, integer_one_node)); - goto dont_grok_size; - } - - if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE - && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE - && TREE_CODE (TREE_TYPE (size)) != BOOLEAN_TYPE) - { - cp_error ("size of array `%D' has non-integer type", - dname); - size = integer_one_node; - } - if (TREE_READONLY_DECL_P (size)) - size = decl_constant_value (size); - if (pedantic && integer_zerop (size)) - cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname); - if (TREE_CONSTANT (size)) - { - int old_flag_pedantic_errors = flag_pedantic_errors; - int old_pedantic = pedantic; - pedantic = flag_pedantic_errors = 1; - /* Always give overflow errors on array subscripts. */ - constant_expression_warning (size); - pedantic = old_pedantic; - flag_pedantic_errors = old_flag_pedantic_errors; - if (INT_CST_LT (size, integer_zero_node)) - { - cp_error ("size of array `%D' is negative", dname); - size = integer_one_node; - } - } - else - { - if (pedantic) - { - if (dname) - cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", - dname); - else - cp_pedwarn ("ANSI C++ forbids variable-size array"); - } - } + declarator = TREE_OPERAND (declarator, 0); - itype - = fold (build_binary_op (MINUS_EXPR, - cp_convert (index_type, size), - cp_convert (index_type, - integer_one_node))); - if (! TREE_CONSTANT (itype)) - itype = variable_size (itype); - else if (TREE_OVERFLOW (itype)) - { - error ("overflow in array dimension"); - TREE_OVERFLOW (itype) = 0; - } + type = create_array_type_for_decl (dname, type, size); - /* If we're a parm, we need to have a permanent type so - mangling checks for re-use will work right. If both the - element and index types are permanent, the array type - will be, too. */ - if (decl_context == PARM - && allocation_temporary_p () && TREE_PERMANENT (type)) - { - push_obstacks (&permanent_obstack, &permanent_obstack); - itype = build_index_type (itype); - pop_obstacks (); - } - else - itype = build_index_type (itype); - - dont_grok_size: - resume_momentary (yes); + /* VLAs never work as fields. */ + if (decl_context == FIELD && !processing_template_decl + && TREE_CODE (type) == ARRAY_TYPE + && TYPE_DOMAIN (type) != NULL_TREE + && !TREE_CONSTANT (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))) + { + error ("size of member `%D' is not constant", dname); + /* Proceed with arbitrary constant size, so that offset + computations don't get confused. */ + type = create_array_type_for_decl (dname, TREE_TYPE (type), + integer_one_node); } - type = build_cplus_array_type (type, itype); ctype = NULL_TREE; } break; @@ -10502,7 +10600,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) { tree arg_types; int funcdecl_p; - tree inner_parms = TREE_OPERAND (declarator, 1); + tree inner_parms = CALL_DECLARATOR_PARMS (declarator); tree inner_decl = TREE_OPERAND (declarator, 0); /* Declaring a function type. @@ -10528,30 +10626,30 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) inner_decl = TREE_OPERAND (inner_decl, 1); - if (inner_decl && TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR) + if (inner_decl && TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR) inner_decl = dname; /* Pick up type qualifiers which should be applied to `this'. */ - quals = TREE_OPERAND (declarator, 2); + quals = CALL_DECLARATOR_QUALS (declarator); /* Pick up the exception specifications. */ - raises = TREE_TYPE (declarator); + raises = CALL_DECLARATOR_EXCEPTION_SPEC (declarator); /* Say it's a definition only for the CALL_EXPR closest to the identifier. */ funcdecl_p - = inner_decl + = inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE - || TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR + || TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR || TREE_CODE (inner_decl) == BIT_NOT_EXPR); - + if (ctype == NULL_TREE && decl_context == FIELD && funcdecl_p && (friendp == 0 || dname == current_class_name)) ctype = current_class_type; - if (ctype && return_type == return_conversion) + if (ctype && sfk == sfk_conversion) TYPE_HAS_CONVERSION (ctype) = 1; if (ctype && constructor_name (ctype) == dname) { @@ -10562,21 +10660,22 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (flags == DTOR_FLAG) { - /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may - not be declared const or volatile. A destructor - may not be static. */ + /* ISO C++ 12.4/2. A destructor may not be + declared const or volatile. A destructor may + not be static. */ if (staticp == 2) error ("destructor cannot be static member function"); if (quals) { - cp_error ("destructors may not be `%s'", + error ("destructors may not be `%s'", IDENTIFIER_POINTER (TREE_VALUE (quals))); quals = NULL_TREE; } if (decl_context == FIELD) { - if (! member_function_or_else (ctype, current_class_type, - "destructor for alien class `%s' cannot be a member")) + if (! member_function_or_else (ctype, + current_class_type, + flags)) return void_type_node; } } @@ -10584,9 +10683,10 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) { if (explicitp == 1) explicitp = 2; - /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may - not be declared const or volatile. A constructor may - not be virtual. A constructor may not be static. */ + /* ISO C++ 12.1. A constructor may not be + declared const or volatile. A constructor may + not be virtual. A constructor may not be + static. */ if (staticp == 2) error ("constructor cannot be static member function"); if (virtualp) @@ -10596,32 +10696,26 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) } if (quals) { - cp_error ("constructors may not be `%s'", + error ("constructors may not be `%s'", IDENTIFIER_POINTER (TREE_VALUE (quals))); quals = NULL_TREE; - } + } { RID_BIT_TYPE tmp_bits; - bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof (RID_BIT_TYPE)); + memcpy (&tmp_bits, &specbits, sizeof (RID_BIT_TYPE)); RIDBIT_RESET (RID_INLINE, tmp_bits); RIDBIT_RESET (RID_STATIC, tmp_bits); if (RIDBIT_ANY_SET (tmp_bits)) error ("return value type specifier for constructor ignored"); } - type = build_pointer_type (ctype); - if (decl_context == FIELD - && IS_SIGNATURE (current_class_type)) - { - error ("constructor not allowed in signature"); - return void_type_node; - } - else if (decl_context == FIELD) + if (decl_context == FIELD) { - if (! member_function_or_else (ctype, current_class_type, - "constructor for alien class `%s' cannot be member")) + if (! member_function_or_else (ctype, + current_class_type, + flags)) return void_type_node; TYPE_HAS_CONSTRUCTOR (ctype) = 1; - if (return_type != return_ctor) + if (sfk != sfk_constructor) return NULL_TREE; } } @@ -10642,7 +10736,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (decl_context == NORMAL) error ("friend declaration not in class definition"); if (current_function_decl && funcdef_flag) - cp_error ("can't define friend function `%s' in a local class definition", + error ("can't define friend function `%s' in a local class definition", name); } @@ -10654,7 +10748,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* FIXME: This is where default args should be fully processed. */ - arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0); + arg_types = grokparms (inner_parms); if (declarator && flags == DTOR_FLAG) { @@ -10663,13 +10757,10 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) want the underlying IDENTIFIER. */ if (TREE_CODE (declarator) == BIT_NOT_EXPR) declarator = TREE_OPERAND (declarator, 0); - - if (strict_prototype == 0 && arg_types == NULL_TREE) - arg_types = void_list_node; - else if (arg_types == NULL_TREE - || arg_types != void_list_node) + + if (arg_types != void_list_node) { - cp_error ("destructors may not have parameters"); + error ("destructors may not have parameters"); arg_types = void_list_node; last_function_parms = NULL_TREE; } @@ -10710,7 +10801,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE)) { - cp_error ("cannot declare pointer to `%#T' member", + error ("cannot declare pointer to `%#T' member", TREE_TYPE (type)); type = TREE_TYPE (type); } @@ -10722,31 +10813,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) but to the target of the pointer. */ type_quals = TYPE_UNQUALIFIED; - if (IS_SIGNATURE (type)) - { - if (TREE_CODE (declarator) == ADDR_EXPR) - { - if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE - && TYPE_SIZE (type)) - cp_warning ("empty signature `%T' used in signature reference declaration", - type); -#if 0 - type = build_signature_reference_type (type); -#else - sorry ("signature reference"); - return NULL_TREE; -#endif - } - else - { - if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE - && TYPE_SIZE (type)) - cp_warning ("empty signature `%T' used in signature pointer declaration", - type); - type = build_signature_pointer_type (type); - } - } - else if (TREE_CODE (declarator) == ADDR_EXPR) + if (TREE_CODE (declarator) == ADDR_EXPR) { if (TREE_CODE (type) == VOID_TYPE) error ("invalid type: `void &'"); @@ -10860,7 +10927,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) TREE_COMPLEXITY (declarator) = current_class_depth; } else - my_friendly_abort (16); + abort (); if (TREE_OPERAND (declarator, 0) == NULL_TREE) { @@ -10874,16 +10941,26 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) ctype = TREE_OPERAND (declarator, 0); t = ctype; - while (t != NULL_TREE && CLASS_TYPE_P (t)) + while (t != NULL_TREE && CLASS_TYPE_P (t)) { - if (CLASSTYPE_TEMPLATE_INFO (t) && - !CLASSTYPE_TEMPLATE_SPECIALIZATION (t)) + /* You're supposed to have one `template <...>' + for every template class, but you don't need one + for a full specialization. For example: + + template <class T> struct S{}; + template <> struct S<int> { void f(); }; + void S<int>::f () {} + + is correct; there shouldn't be a `template <>' for + the definition of `S<int>::f'. */ + if (CLASSTYPE_TEMPLATE_INFO (t) + && (CLASSTYPE_TEMPLATE_INSTANTIATION (t) + || uses_template_parms (CLASSTYPE_TI_ARGS (t))) + && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t))) template_count += 1; + t = TYPE_MAIN_DECL (t); - if (DECL_LANG_SPECIFIC (t)) - t = DECL_CLASS_CONTEXT (t); - else - t = NULL_TREE; + t = DECL_CONTEXT (t); } if (sname == NULL_TREE) @@ -10903,24 +10980,23 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) Is this ill-formed? */ if (pedantic) - cp_pedwarn ("extra qualification `%T::' on member `%s' ignored", + pedwarn ("extra qualification `%T::' on member `%s' ignored", ctype, name); } else if (TREE_CODE (type) == FUNCTION_TYPE) { - if (current_class_type == NULL_TREE - || friendp) + if (current_class_type == NULL_TREE || friendp) type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type)); else { - cp_error ("cannot declare member function `%T::%s' within `%T'", + error ("cannot declare member function `%T::%s' within `%T'", ctype, name, current_class_type); return void_type_node; } } else if (RIDBIT_SETP (RID_TYPEDEF, specbits) - || TYPE_SIZE (complete_type (ctype)) != NULL_TREE) + || COMPLETE_TYPE_P (complete_type (ctype))) { /* Have to move this code elsewhere in this function. this code is used for i.e., typedef int A::M; M *pm; @@ -10929,29 +11005,22 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (current_class_type) { - cp_error ("cannot declare member `%T::%s' within `%T'", + error ("cannot declare member `%T::%s' within `%T'", ctype, name, current_class_type); return void_type_node; } type = build_offset_type (ctype, type); } - else if (uses_template_parms (ctype)) - { - if (TREE_CODE (type) == FUNCTION_TYPE) - type - = build_cplus_method_type (ctype, TREE_TYPE (type), - TYPE_ARG_TYPES (type)); - } else - { - cp_error ("structure `%T' not yet defined", ctype); - return error_mark_node; + { + incomplete_type_error (NULL_TREE, ctype); + return error_mark_node; } declarator = sname; } else if (TREE_CODE (sname) == SCOPE_REF) - my_friendly_abort (17); + abort (); else { done_scoping: @@ -10986,41 +11055,68 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) break; default: - my_friendly_abort (158); + abort (); } } - /* See the comment for the TREE_LIST case, above. */ - if (inner_attrs) + if (returned_attrs) { - if (! ignore_attrs) - decl_attributes (type, inner_attrs, NULL_TREE); - else if (attrlist) - TREE_VALUE (attrlist) = chainon (inner_attrs, TREE_VALUE (attrlist)); + if (attrlist) + *attrlist = chainon (returned_attrs, *attrlist); else - attrlist = build_decl_list (NULL_TREE, inner_attrs); + attrlist = &returned_attrs; } /* Now TYPE has the actual type. */ - if (explicitp == 1) + /* Did array size calculations overflow? */ + + if (TREE_CODE (type) == ARRAY_TYPE + && COMPLETE_TYPE_P (type) + && TREE_OVERFLOW (TYPE_SIZE (type))) + { + error ("size of array `%s' is too large", name); + /* If we proceed with the array type as it is, we'll eventually + crash in tree_low_cst(). */ + type = error_mark_node; + } + + if (explicitp == 1 || (explicitp && friendp)) { - error ("only constructors can be declared `explicit'"); + /* [dcl.fct.spec] The explicit specifier shall only be used in + declarations of constructors within a class definition. */ + error ("only declarations of constructors can be `explicit'"); explicitp = 0; } if (RIDBIT_SETP (RID_MUTABLE, specbits)) { - if (type_quals & TYPE_QUAL_CONST) + if (current_class_name == NULL_TREE || decl_context == PARM || friendp) + { + error ("non-member `%s' cannot be declared `mutable'", name); + RIDBIT_RESET (RID_MUTABLE, specbits); + } + else if (decl_context == TYPENAME || RIDBIT_SETP (RID_TYPEDEF, specbits)) { - error ("const `%s' cannot be declared `mutable'", name); + error ("non-object member `%s' cannot be declared `mutable'", name); RIDBIT_RESET (RID_MUTABLE, specbits); } + else if (TREE_CODE (type) == FUNCTION_TYPE + || TREE_CODE (type) == METHOD_TYPE) + { + error ("function `%s' cannot be declared `mutable'", name); + RIDBIT_RESET (RID_MUTABLE, specbits); + } else if (staticp) { error ("static `%s' cannot be declared `mutable'", name); RIDBIT_RESET (RID_MUTABLE, specbits); } + else if (type_quals & TYPE_QUAL_CONST) + { + error ("const `%s' cannot be declared `mutable'", name); + RIDBIT_RESET (RID_MUTABLE, specbits); + } } if (declarator == NULL_TREE @@ -11031,12 +11127,12 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* OK */; else if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) { - cp_error ("template-id `%D' used as a declarator", declarator); + error ("template-id `%D' used as a declarator", declarator); declarator = dname; } else /* Unexpected declarator format. */ - my_friendly_abort (990210); + abort (); /* If this is declaring a typedef name, return a TYPE_DECL. */ @@ -11052,38 +11148,31 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (decl_context == FIELD) { if (declarator == constructor_name (current_class_type)) - cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class", + pedwarn ("ISO C++ forbids nested type `%D' with same name as enclosing class", declarator); decl = build_lang_decl (TYPE_DECL, declarator, type); - if (IS_SIGNATURE (current_class_type) && opaque_typedef) - SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; } else { - /* Make sure this typedef lives as long as its type, - since it might be used as a template parameter. */ - if (type != error_mark_node) - push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); decl = build_decl (TYPE_DECL, declarator, type); - if (type != error_mark_node) - pop_obstacks (); + if (!current_function_decl) + DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); } - - /* If the user declares "struct {...} foo" then `foo' will have - an anonymous name. Fill that name in now. Nothing can - refer to it, so nothing needs know about the name change. - The TYPE_NAME field was filled in by build_struct_xref. */ + + /* If the user declares "typedef struct {...} foo" then the + struct will have an anonymous name. Fill that name in now. + Nothing can refer to it, so nothing needs know about the name + change. */ if (type != error_mark_node + && declarator && TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL - && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) + && TYPE_ANONYMOUS_P (type) + && cp_type_quals (type) == TYPE_UNQUALIFIED) { tree oldname = TYPE_NAME (type); tree t; - /* FIXME: This is bogus; we should not be doing this for - cv-qualified types. */ - /* Replace the anonymous name with the real name everywhere. */ lookup_tag_reverse (type, declarator); for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) @@ -11097,23 +11186,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) type is a (non-primary) template. The name for the template needs updating as well. */ if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type)) - DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) + DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = TYPE_IDENTIFIER (type); - /* XXX Temporarily set the scope. - When returning, start_decl expects it as NULL_TREE, - and will then then set it using pushdecl. */ - my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 980404); - if (current_class_type) - DECL_CONTEXT (decl) = current_class_type; - else - DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); - - DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl); - DECL_ASSEMBLER_NAME (decl) - = get_identifier (build_overload_name (type, 1, 1)); - DECL_CONTEXT (decl) = NULL_TREE; - /* FIXME remangle member functions; member functions of a type with external linkage have external linkage. */ } @@ -11128,7 +11203,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (ctype == NULL_TREE) { if (TREE_CODE (type) != METHOD_TYPE) - cp_error_at ("invalid type qualifier for non-method type", decl); + cp_error_at ("invalid type qualifier for non-member function type", decl); else ctype = TYPE_METHOD_BASETYPE (type); } @@ -11140,9 +11215,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; - if (RIDBIT_SETP (RID_MUTABLE, specbits)) - error ("non-object member `%s' cannot be declared mutable", name); - bad_specifiers (decl, "type", virtualp, quals != NULL_TREE, inlinep, friendp, raises != NULL_TREE); @@ -11158,12 +11230,33 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) a distinct type, so that each identifier's size can be controlled separately by its own initializer. */ - if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE - && TYPE_DOMAIN (type) == NULL_TREE) + if (type != 0 && typedef_type != 0 + && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0 + && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)) { 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. */ @@ -11172,48 +11265,72 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* Note that the grammar rejects storage classes in typenames, fields or parameters. */ if (type_quals != TYPE_UNQUALIFIED) - { - if (IS_SIGNATURE (type)) - error ("type qualifiers specified for signature type"); - type_quals = TYPE_UNQUALIFIED; - } + type_quals = TYPE_UNQUALIFIED; /* Special case: "friend class foo" looks like a TYPENAME context. */ if (friendp) { if (type_quals != TYPE_UNQUALIFIED) { - cp_error ("type qualifiers specified for friend class declaration"); + error ("type qualifiers specified for friend class declaration"); type_quals = TYPE_UNQUALIFIED; } if (inlinep) { - cp_error ("`inline' specified for friend class declaration"); + error ("`inline' specified for friend class declaration"); inlinep = 0; } + /* Until core issue 180 is resolved, allow 'friend typename A::B'. + But don't allow implicit typenames except with a class-key. */ + if (!current_aggr && (TREE_CODE (type) != TYPENAME_TYPE + || IMPLICIT_TYPENAME_P (type))) + { + if (TREE_CODE (type) == TEMPLATE_TYPE_PARM) + pedwarn ("template parameters cannot be friends"); + else if (TREE_CODE (type) == TYPENAME_TYPE) + pedwarn ("\ +friend declaration requires class-key, i.e. `friend class %T::%T'", + constructor_name (current_class_type), + TYPE_IDENTIFIER (type)); + else + pedwarn ("\ +friend declaration requires class-key, i.e. `friend %#T'", + type); + } + /* Only try to do this stuff if we didn't already give up. */ if (type != integer_type_node) { + /* DR 209. The friendly class does not need to be accessible + in the scope of the class granting friendship. */ + skip_type_access_control (); + /* A friendly class? */ if (current_class_type) make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type)); else - error ("trying to make class `%s' a friend of global scope", - TYPE_NAME_STRING (type)); + error ("trying to make class `%T' a friend of global scope", + type); + type = void_type_node; } } else if (quals) { - tree dummy = build_decl (TYPE_DECL, declarator, type); if (ctype == NULL_TREE) { - my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); - ctype = TYPE_METHOD_BASETYPE (type); + if (TREE_CODE (type) != METHOD_TYPE) + error ("invalid qualifiers on non-member function type"); + else + ctype = TYPE_METHOD_BASETYPE (type); + } + if (ctype) + { + tree dummy = build_decl (TYPE_DECL, declarator, type); + grok_method_quals (ctype, dummy, quals); + type = TREE_TYPE (dummy); } - grok_method_quals (ctype, dummy, quals); - type = TREE_TYPE (dummy); } return type; @@ -11223,7 +11340,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) && TREE_CODE (type) != UNION_TYPE && ! bitfield) { - cp_error ("abstract declarator `%T' used as declaration", type); + error ("abstract declarator `%T' used as declaration", type); declarator = make_anon_name (); } @@ -11239,7 +11356,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) else if (TREE_CODE (declarator) == IDENTIFIER_NODE) { if (IDENTIFIER_OPNAME_P (declarator)) - my_friendly_abort (356); + abort (); else error ("variable or field `%s' declared void", name); } @@ -11270,13 +11387,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) type = build_pointer_type (type); else if (TREE_CODE (type) == OFFSET_TYPE) type = build_pointer_type (type); - else if (TREE_CODE (type) == VOID_TYPE && declarator) - { - error ("declaration of `%s' as void", name); - return NULL_TREE; - } } - + { register tree decl; @@ -11286,16 +11398,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, inlinep, friendp, raises != NULL_TREE); - if (current_class_type - && IS_SIGNATURE (current_class_type)) - { - if (inlinep) - error ("parameter of signature member function declared `inline'"); - if (RIDBIT_SETP (RID_AUTO, specbits)) - error ("parameter of signature member function declared `auto'"); - if (RIDBIT_SETP (RID_REGISTER, specbits)) - error ("parameter of signature member function declared `register'"); - } /* Compute the type actually passed in the parmlist, for the case where there is no prototype. @@ -11315,7 +11417,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) else if (in_namespace && !friendp) { /* Something like struct S { int N::j; }; */ - cp_error ("invalid use of `::'"); + error ("invalid use of `::'"); decl = NULL_TREE; } else if (TREE_CODE (type) == FUNCTION_TYPE) @@ -11327,7 +11429,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) typedefs. */ if (friendp && declarator == ridpointers[(int) RID_SIGNED]) { - cp_error ("function `%D' cannot be declared friend", + error ("function `%D' cannot be declared friend", declarator); friendp = 0; } @@ -11339,7 +11441,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (ctype == NULL_TREE) { - cp_error ("can't make `%D' into a method -- not in a class", + error ("can't make `%D' into a method -- not in a class", declarator); return void_type_node; } @@ -11348,19 +11450,19 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) ARM 9.5 */ if (virtualp && TREE_CODE (ctype) == UNION_TYPE) { - cp_error ("function `%D' declared virtual inside a union", + error ("function `%D' declared virtual inside a union", declarator); return void_type_node; } - if (declarator == ansi_opname[(int) NEW_EXPR] - || declarator == ansi_opname[(int) VEC_NEW_EXPR] - || declarator == ansi_opname[(int) DELETE_EXPR] - || declarator == ansi_opname[(int) VEC_DELETE_EXPR]) + if (declarator == ansi_opname (NEW_EXPR) + || declarator == ansi_opname (VEC_NEW_EXPR) + || declarator == ansi_opname (DELETE_EXPR) + || declarator == ansi_opname (VEC_DELETE_EXPR)) { if (virtualp) { - cp_error ("`%D' cannot be declared virtual, since it is always static", + error ("`%D' cannot be declared virtual, since it is always static", declarator); virtualp = 0; } @@ -11371,11 +11473,11 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) } /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ - function_context = (ctype != NULL_TREE) ? - hack_decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE; + function_context = (ctype != NULL_TREE) ? + decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE; publicp = (! friendp || ! staticp) && function_context == NULL_TREE; - decl = grokfndecl (ctype, type, + decl = grokfndecl (ctype, type, TREE_CODE (declarator) != TEMPLATE_ID_EXPR ? declarator : dname, declarator, @@ -11386,8 +11488,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) return decl; #if 0 /* This clobbers the attrs stored in `decl' from `attrlist'. */ - /* The decl and setting of decl_machine_attr is also turned off. */ - decl = build_decl_attribute_variant (decl, decl_machine_attr); + /* The decl and setting of decl_attr is also turned off. */ + decl = build_decl_attribute_variant (decl, decl_attr); #endif /* [class.conv.ctor] @@ -11404,23 +11506,12 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* The constructor can be called with exactly one parameter if there is at least one parameter, and any subsequent parameters have default arguments. - We don't look at the first parameter, which is - really just the `this' parameter for the new - object. */ - tree arg_types = - TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))); - - /* Skip the `in_chrg' argument too, if present. */ - if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (decl))) - arg_types = TREE_CHAIN (arg_types); - - /* And the `vlist' argument. */ - if (TYPE_USES_PVBASES (DECL_CONTEXT (decl))) - arg_types = TREE_CHAIN (arg_types); + Ignore any compiler-added parms. */ + tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (decl); if (arg_types == void_list_node - || (arg_types - && TREE_CHAIN (arg_types) + || (arg_types + && TREE_CHAIN (arg_types) && TREE_CHAIN (arg_types) != void_list_node && !TREE_PURPOSE (TREE_CHAIN (arg_types)))) DECL_NONCONVERTING_P (decl) = 1; @@ -11440,13 +11531,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) return NULL_TREE; } else if (!staticp && ! processing_template_decl - && TYPE_SIZE (complete_type (type)) == NULL_TREE + && !COMPLETE_TYPE_P (complete_type (type)) && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) { if (declarator) - cp_error ("field `%D' has incomplete type", declarator); + error ("field `%D' has incomplete type", declarator); else - cp_error ("name `%T' has incomplete type", type); + error ("name `%T' has incomplete type", type); /* If we're instantiating a template, tell them which instantiation made the field's type be incomplete. */ @@ -11455,7 +11546,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type)) && declspecs && TREE_VALUE (declspecs) && TREE_TYPE (TREE_VALUE (declspecs)) == type) - cp_error (" in instantiation of template `%T'", + error (" in instantiation of template `%T'", current_class_type); type = error_mark_node; @@ -11465,7 +11556,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) { if (friendp) { - error ("`%s' is neither function nor method; cannot be declared friend", + error ("`%s' is neither function nor member function; cannot be declared friend", IDENTIFIER_POINTER (declarator)); friendp = 0; } @@ -11475,32 +11566,33 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (friendp) { /* Friends are treated specially. */ + tree t = NULL_TREE; + + /* DR 209. The friend does not need to be accessible at this + point. */ + skip_type_access_control (); + if (ctype == current_class_type) warning ("member functions are implicitly friends of their class"); - else - { - tree t = NULL_TREE; - if (decl && DECL_NAME (decl)) - { - if (template_class_depth (current_class_type) == 0) - { - decl - = check_explicit_specialization - (declarator, decl, - template_count, 2 * (funcdef_flag != 0) + 4); - if (decl == error_mark_node) - return error_mark_node; - } - t = do_friend (ctype, declarator, decl, - last_function_parms, attrlist, flags, quals, - funcdef_flag); - } - if (t && funcdef_flag) - return t; - - return void_type_node; - } + if (decl && DECL_NAME (decl)) + { + if (template_class_depth (current_class_type) == 0) + { + decl = check_explicit_specialization + (declarator, decl, + template_count, 2 * (funcdef_flag != 0) + 4); + if (decl == error_mark_node) + return error_mark_node; + } + + t = do_friend (ctype, declarator, decl, + last_function_parms, *attrlist, flags, quals, + funcdef_flag); + } + if (t && funcdef_flag) + return t; + return void_type_node; } /* Structure field. It may not be a function, except for C++ */ @@ -11513,19 +11605,19 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) { /* An attempt is being made to initialize a non-static member. But, from [class.mem]: - + 4 A member-declarator can contain a constant-initializer only if it declares a static member (_class.static_) of integral or enumeration - type, see _class.static.data_. + type, see _class.static.data_. This used to be relatively common practice, but the rest of the compiler does not correctly handle the initialization unless the member is static so we make it static below. */ - cp_pedwarn ("ANSI C++ forbids initialization of member `%D'", + pedwarn ("ISO C++ forbids initialization of member `%D'", declarator); - cp_pedwarn ("making `%D' static", declarator); + pedwarn ("making `%D' static", declarator); staticp = 1; } @@ -11544,27 +11636,27 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* 9.2p13 [class.mem] */ if (declarator == constructor_name (current_class_type) - /* Divergence from the standard: In extern "C", we - allow non-static data members here, because C does - and /usr/include/netinet/in.h uses that. */ - && (staticp || ! in_system_header)) - cp_pedwarn ("ANSI C++ forbids data member `%D' with same name as enclosing class", + /* The standard does not allow non-static data members + here either, but we agreed at the 10/99 meeting + to change that in TC 1 so that they are allowed in + classes with no user-defined constructors. */ + && staticp) + pedwarn ("ISO C++ forbids static data member `%D' with same name as enclosing class", declarator); if (staticp) { - /* C++ allows static class members. - All other work for this is done by grokfield. - This VAR_DCL is built by build_lang_field_decl. - All other VAR_DECLs are built by build_decl. */ - decl = build_lang_field_decl (VAR_DECL, declarator, type); + /* C++ allows static class members. All other work + for this is done by grokfield. */ + decl = build_lang_decl (VAR_DECL, declarator, type); TREE_STATIC (decl) = 1; /* In class context, 'static' means public access. */ TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = 1; } else { - decl = build_lang_field_decl (FIELD_DECL, declarator, type); + decl = build_decl (FIELD_DECL, declarator, type); + DECL_NONADDRESSABLE_P (decl) = bitfield; if (RIDBIT_SETP (RID_MUTABLE, specbits)) { DECL_MUTABLE_P (decl) = 1; @@ -11607,7 +11699,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) else pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name); } - + if (ctype == NULL_TREE) { if (virtualp) @@ -11628,7 +11720,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) decl = grokfndecl (ctype, type, original_name, declarator, virtualp, flags, quals, raises, 1, friendp, - publicp, inlinep, funcdef_flag, + publicp, inlinep, funcdef_flag, template_count, in_namespace); if (decl == NULL_TREE) return NULL_TREE; @@ -11641,7 +11733,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) declaring main to be static. */ if (TREE_CODE (type) == METHOD_TYPE) { - cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl); + pedwarn ("cannot declare member function `%D' to have static linkage", decl); illegal_static = 1; } else if (current_function_decl) @@ -11663,9 +11755,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* It's a variable. */ /* An uninitialized decl with `extern' is a reference. */ - decl = grokvardecl (type, declarator, &specbits, - initialized, - (type_quals & TYPE_QUAL_CONST) != 0, + decl = grokvardecl (type, declarator, &specbits, + initialized, + (type_quals & TYPE_QUAL_CONST) != 0, in_namespace); bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, inlinep, friendp, raises != NULL_TREE); @@ -11675,28 +11767,25 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) DECL_CONTEXT (decl) = ctype; if (staticp == 1) { - cp_pedwarn ("static member `%D' re-declared as static", decl); + pedwarn ("`static' may not be used when defining (as opposed to declaring) a static data member"); staticp = 0; RIDBIT_RESET (RID_STATIC, specbits); } if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl)) { - cp_error ("static member `%D' declared `register'", decl); + error ("static member `%D' declared `register'", decl); RIDBIT_RESET (RID_REGISTER, specbits); } if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic) { - cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage", + pedwarn ("cannot explicitly declare member `%#D' to have extern linkage", decl); RIDBIT_RESET (RID_EXTERN, specbits); } } } - if (RIDBIT_SETP (RID_MUTABLE, specbits)) - { - error ("`%s' cannot be declared mutable", name); - } + my_friendly_assert (!RIDBIT_SETP (RID_MUTABLE, specbits), 19990927); /* Record `register' declaration for warnings on & and in case doing stupid register allocation. */ @@ -11710,9 +11799,11 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (RIDBIT_SETP (RID_STATIC, specbits)) DECL_THIS_STATIC (decl) = 1; - /* Record constancy and volatility. */ - /* FIXME: Disallow `restrict' pointer-to-member declarations. */ - c_apply_type_quals_to_decl (type_quals, decl); + /* Record constancy and volatility. There's no need to do this + when processing a template; we'll do this for the instantiated + declaration based on the type of DECL. */ + if (!processing_template_decl) + c_apply_type_quals_to_decl (type_quals, decl); return decl; } @@ -11753,42 +11844,60 @@ static void require_complete_types_for_parms (parms) tree parms; { - while (parms) + for (; parms; parms = TREE_CHAIN (parms)) { - tree type = TREE_TYPE (parms); - if (TYPE_SIZE (complete_type (type)) == NULL_TREE) - { - if (DECL_NAME (parms)) - error ("parameter `%s' has incomplete type", - IDENTIFIER_POINTER (DECL_NAME (parms))); - else - error ("parameter has incomplete type"); - TREE_TYPE (parms) = error_mark_node; - } - else + if (VOID_TYPE_P (TREE_TYPE (parms))) + /* grokparms will have already issued an error */ + TREE_TYPE (parms) = error_mark_node; + else if (complete_type_or_else (TREE_TYPE (parms), parms)) layout_decl (parms, 0); - - parms = TREE_CHAIN (parms); + else + TREE_TYPE (parms) = error_mark_node; } } -/* Returns DECL if DECL is a local variable (or parameter). Returns - NULL_TREE otherwise. */ +/* Returns non-zero if T is a local variable. */ -static tree +int local_variable_p (t) tree t; { - if ((TREE_CODE (t) == VAR_DECL + if ((TREE_CODE (t) == VAR_DECL /* A VAR_DECL with a context that is a _TYPE is a static data member. */ && !TYPE_P (CP_DECL_CONTEXT (t)) /* Any other non-local variable must be at namespace scope. */ - && TREE_CODE (CP_DECL_CONTEXT (t)) != NAMESPACE_DECL) + && !DECL_NAMESPACE_SCOPE_P (t)) || (TREE_CODE (t) == PARM_DECL)) - return t; + return 1; - return NULL_TREE; + return 0; +} + +/* Returns non-zero if T is an automatic local variable or a label. + (These are the declarations that need to be remapped when the code + containing them is duplicated.) */ + +int +nonstatic_local_decl_p (t) + tree t; +{ + return ((local_variable_p (t) && !TREE_STATIC (t)) + || TREE_CODE (t) == LABEL_DECL + || TREE_CODE (t) == RESULT_DECL); +} + +/* Like local_variable_p, but suitable for use as a tree-walking + function. */ + +static tree +local_variable_p_walkfn (tp, walk_subtrees, data) + tree *tp; + int *walk_subtrees ATTRIBUTE_UNUSED; + void *data ATTRIBUTE_UNUSED; +{ + return ((local_variable_p (*tp) && !DECL_ARTIFICIAL (*tp)) + ? *tp : NULL_TREE); } /* Check that ARG, which is a default-argument expression for a @@ -11825,7 +11934,7 @@ check_default_argument (decl, arg) else decl_type = TREE_TYPE (decl); - if (arg == error_mark_node + if (arg == error_mark_node || decl == error_mark_node || TREE_TYPE (arg) == error_mark_node || decl_type == error_mark_node) @@ -11834,17 +11943,17 @@ check_default_argument (decl, arg) return error_mark_node; /* [dcl.fct.default] - + A default argument expression is implicitly converted to the parameter type. */ if (!TREE_TYPE (arg) || !can_convert_arg (decl_type, TREE_TYPE (arg), arg)) { if (decl) - cp_error ("default argument for `%#D' has type `%T'", + error ("default argument for `%#D' has type `%T'", decl, TREE_TYPE (arg)); else - cp_error ("default argument for paramter of type `%T' has type `%T'", + error ("default argument for parameter of type `%T' has type `%T'", decl_type, TREE_TYPE (arg)); return error_mark_node; @@ -11853,14 +11962,15 @@ check_default_argument (decl, arg) /* [dcl.fct.default] Local variables shall not be used in default argument - expressions. + expressions. The keyword `this' shall not be used in a default argument of a member function. */ - var = search_tree (arg, local_variable_p); + var = walk_tree_without_duplicates (&arg, local_variable_p_walkfn, + NULL); if (var) { - cp_error ("default argument `%E' uses local variable `%D'", + error ("default argument `%E' uses local variable `%D'", arg, var); return error_mark_node; } @@ -11873,469 +11983,413 @@ check_default_argument (decl, arg) Given the list of things declared inside the parens, return a list of types. - The list we receive can have three kinds of elements: - an IDENTIFIER_NODE for names given without types, - a TREE_LIST node for arguments given as typespecs or names with typespecs, - or void_type_node, to mark the end of an argument list - when additional arguments are not permitted (... was not used). - - FUNCDEF_FLAG is nonzero for a function definition, 0 for - a mere declaration. A nonempty identifier-list gets an error message - when FUNCDEF_FLAG is zero. - If FUNCDEF_FLAG is 1, then parameter types must be complete. - If FUNCDEF_FLAG is -1, then parameter types may be incomplete. - - If all elements of the input list contain types, - we return a list of the types. - If all elements contain no type (except perhaps a void_type_node - at the end), we return a null list. - If some have types and some do not, it is an error, and we - return a null list. - - Also set last_function_parms to either - a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs. - A list of names is converted to a chain of PARM_DECLs - by store_parm_decls so that ultimately it is always a chain of decls. - - Note that in C++, parameters can take default values. These default - values are in the TREE_PURPOSE field of the TREE_LIST. It is - an error to specify default values which are followed by parameters - that have no default values, or an ELLIPSES. For simplicities sake, - only parameters which are specified with their types can take on - default values. */ + We determine whether ellipsis parms are used by PARMLIST_ELLIPSIS_P + flag. If unset, we append void_list_node. A parmlist declared + as `(void)' is accepted as the empty parmlist. + + Also set last_function_parms to the chain of PARM_DECLs. */ static tree -grokparms (first_parm, funcdef_flag) +grokparms (first_parm) tree first_parm; - int funcdef_flag; { tree result = NULL_TREE; tree decls = NULL_TREE; + int ellipsis = !first_parm || PARMLIST_ELLIPSIS_P (first_parm); + tree parm, chain; + int any_error = 0; - if (first_parm != NULL_TREE - && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) - { - if (! funcdef_flag) - pedwarn ("parameter names (without types) in function declaration"); - last_function_parms = first_parm; - return NULL_TREE; - } - else if (first_parm != NULL_TREE - && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST - && TREE_CODE (TREE_VALUE (first_parm)) != VOID_TYPE) - my_friendly_abort (145); - else + my_friendly_assert (!first_parm || TREE_PARMLIST (first_parm), 20001115); + + for (parm = first_parm; parm != NULL_TREE; parm = chain) { - /* Types were specified. This is a list of declarators - each represented as a TREE_LIST node. */ - register tree parm, chain; - int any_init = 0, any_error = 0; + tree type = NULL_TREE; + tree decl = TREE_VALUE (parm); + tree init = TREE_PURPOSE (parm); + tree specs, attrs; + + chain = TREE_CHAIN (parm); + /* @@ weak defense against parse errors. */ + if (TREE_CODE (decl) != VOID_TYPE + && TREE_CODE (decl) != TREE_LIST) + { + /* Give various messages as the need arises. */ + if (TREE_CODE (decl) == STRING_CST) + error ("invalid string constant `%E'", decl); + else if (TREE_CODE (decl) == INTEGER_CST) + error ("invalid integer constant in parameter list, did you forget to give parameter name?"); + continue; + } - if (first_parm != NULL_TREE) - { - tree last_result = NULL_TREE; - tree last_decl = NULL_TREE; + if (parm == void_list_node) + break; - for (parm = first_parm; parm != NULL_TREE; parm = chain) - { - tree type = NULL_TREE, list_node = parm; - register tree decl = TREE_VALUE (parm); - tree init = TREE_PURPOSE (parm); - - chain = TREE_CHAIN (parm); - /* @@ weak defense against parse errors. */ - if (TREE_CODE (decl) != VOID_TYPE - && TREE_CODE (decl) != TREE_LIST) - { - /* Give various messages as the need arises. */ - if (TREE_CODE (decl) == STRING_CST) - cp_error ("invalid string constant `%E'", decl); - else if (TREE_CODE (decl) == INTEGER_CST) - error ("invalid integer constant in parameter list, did you forget to give parameter name?"); - continue; - } + split_specs_attrs (TREE_PURPOSE (decl), &specs, &attrs); + decl = grokdeclarator (TREE_VALUE (decl), specs, + PARM, init != NULL_TREE, &attrs); + if (! decl || TREE_TYPE (decl) == error_mark_node) + continue; - if (TREE_CODE (decl) != VOID_TYPE) - { - decl = grokdeclarator (TREE_VALUE (decl), - TREE_PURPOSE (decl), - PARM, init != NULL_TREE, - NULL_TREE); - if (! decl || TREE_TYPE (decl) == error_mark_node) - continue; - - /* Top-level qualifiers on the parameters are - ignored for function types. */ - type = TYPE_MAIN_VARIANT (TREE_TYPE (decl)); - - if (TREE_CODE (type) == VOID_TYPE) - decl = void_type_node; - else if (TREE_CODE (type) == METHOD_TYPE) - { - if (DECL_NAME (decl)) - /* Cannot use the decl here because - we don't have DECL_CONTEXT set up yet. */ - cp_error ("parameter `%D' invalidly declared method type", - DECL_NAME (decl)); - else - error ("parameter invalidly declared method type"); - type = build_pointer_type (type); - TREE_TYPE (decl) = type; - } - else if (TREE_CODE (type) == OFFSET_TYPE) - { - if (DECL_NAME (decl)) - cp_error ("parameter `%D' invalidly declared offset type", - DECL_NAME (decl)); - else - error ("parameter invalidly declared offset type"); - type = build_pointer_type (type); - TREE_TYPE (decl) = type; - } - else if (TREE_CODE (type) == RECORD_TYPE - && TYPE_LANG_SPECIFIC (type) - && CLASSTYPE_ABSTRACT_VIRTUALS (type)) - { - abstract_virtuals_error (decl, type); - any_error = 1; /* Seems like a good idea. */ - } - else if (TREE_CODE (type) == RECORD_TYPE - && TYPE_LANG_SPECIFIC (type) - && IS_SIGNATURE (type)) - { - signature_error (decl, type); - any_error = 1; /* Seems like a good idea. */ - } - else if (POINTER_TYPE_P (type)) - { - tree t = type; - while (POINTER_TYPE_P (t) - || (TREE_CODE (t) == ARRAY_TYPE - && TYPE_DOMAIN (t) != NULL_TREE)) - t = TREE_TYPE (t); - if (TREE_CODE (t) == ARRAY_TYPE) - cp_error ("parameter type `%T' includes %s to array of unknown bound", - type, - TYPE_PTR_P (type) ? "pointer" : "reference"); - } - } - - if (TREE_CODE (decl) == VOID_TYPE) - { - if (result == NULL_TREE) - { - result = void_list_node; - last_result = result; - } - else - { - TREE_CHAIN (last_result) = void_list_node; - last_result = void_list_node; - } - if (chain - && (chain != void_list_node || TREE_CHAIN (chain))) - error ("`void' in parameter list must be entire list"); - break; - } + if (attrs) + cplus_decl_attributes (&decl, attrs, 0); - /* Since there is a prototype, args are passed in their own types. */ - DECL_ARG_TYPE (decl) = TREE_TYPE (decl); -#ifdef PROMOTE_PROTOTYPES - if ((TREE_CODE (type) == INTEGER_TYPE - || TREE_CODE (type) == ENUMERAL_TYPE) - && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) - DECL_ARG_TYPE (decl) = integer_type_node; -#endif - if (!any_error && init) - { - any_init++; - init = check_default_argument (decl, init); - } - else - init = NULL_TREE; + type = TREE_TYPE (decl); + if (VOID_TYPE_P (type)) + { + if (same_type_p (type, void_type_node) + && !DECL_NAME (decl) && !result && !chain && !ellipsis) + /* this is a parmlist of `(void)', which is ok. */ + break; + incomplete_type_error (decl, type); + /* It's not a good idea to actually create parameters of + type `void'; other parts of the compiler assume that a + void type terminates the parameter list. */ + type = error_mark_node; + TREE_TYPE (decl) = error_mark_node; + } - if (decls == NULL_TREE) - { - decls = decl; - last_decl = decls; - } - else - { - TREE_CHAIN (last_decl) = decl; - last_decl = decl; - } - if (! current_function_decl && TREE_PERMANENT (list_node)) - { - TREE_PURPOSE (list_node) = init; - TREE_VALUE (list_node) = type; - TREE_CHAIN (list_node) = NULL_TREE; - } - else - list_node = saveable_tree_cons (init, type, NULL_TREE); - if (result == NULL_TREE) - { - result = list_node; - last_result = result; - } - else - { - TREE_CHAIN (last_result) = list_node; - last_result = list_node; - } + if (type != error_mark_node) + { + /* Top-level qualifiers on the parameters are + ignored for function types. */ + type = TYPE_MAIN_VARIANT (type); + if (TREE_CODE (type) == METHOD_TYPE) + { + error ("parameter `%D' invalidly declared method type", decl); + type = build_pointer_type (type); + TREE_TYPE (decl) = type; + } + else if (TREE_CODE (type) == OFFSET_TYPE) + { + error ("parameter `%D' invalidly declared offset type", decl); + type = build_pointer_type (type); + TREE_TYPE (decl) = type; + } + else if (abstract_virtuals_error (decl, type)) + any_error = 1; /* Seems like a good idea. */ + else if (POINTER_TYPE_P (type)) + { + /* [dcl.fct]/6, parameter types cannot contain pointers + (references) to arrays of unknown bound. */ + tree t = TREE_TYPE (type); + int ptr = TYPE_PTR_P (type); + + while (1) + { + if (TYPE_PTR_P (t)) + ptr = 1; + else if (TREE_CODE (t) != ARRAY_TYPE) + break; + else if (!TYPE_DOMAIN (t)) + break; + t = TREE_TYPE (t); + } + if (TREE_CODE (t) == ARRAY_TYPE) + error ("parameter `%D' includes %s to array of unknown bound `%T'", + decl, ptr ? "pointer" : "reference", t); } - if (last_result) - TREE_CHAIN (last_result) = NULL_TREE; - /* If there are no parameters, and the function does not end - with `...', then last_decl will be NULL_TREE. */ - if (last_decl != NULL_TREE) - TREE_CHAIN (last_decl) = NULL_TREE; + + DECL_ARG_TYPE (decl) = TREE_TYPE (decl); + if (PROMOTE_PROTOTYPES + && INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) + DECL_ARG_TYPE (decl) = integer_type_node; + if (!any_error && init) + init = check_default_argument (decl, init); + else + init = NULL_TREE; } - } + TREE_CHAIN (decl) = decls; + decls = decl; + result = tree_cons (init, type, result); + } + decls = nreverse (decls); + result = nreverse (result); + if (!ellipsis) + result = chainon (result, void_list_node); last_function_parms = decls; return result; } -/* Called from the parser to update an element of TYPE_ARG_TYPES for some - FUNCTION_TYPE with the newly parsed version of its default argument, which - was previously digested as text. See snarf_defarg et al in lex.c. */ - -void -replace_defarg (arg, init) - tree arg, init; -{ - if (! processing_template_decl - && ! can_convert_arg (TREE_VALUE (arg), TREE_TYPE (init), init)) - cp_pedwarn ("invalid type `%T' for default argument to `%T'", - TREE_TYPE (init), TREE_VALUE (arg)); - TREE_PURPOSE (arg) = init; -} -/* Return 1 if D copies its arguments. This is used to test for copy - constructors and copy assignment operators. */ +/* D is a constructor or overloaded `operator='. + + Let T be the class in which D is declared. Then, this function + returns: + + -1 if D's is an ill-formed constructor or copy assignment operator + whose first parameter is of type `T'. + 0 if D is not a copy constructor or copy assignment + operator. + 1 if D is a copy constructor or copy assignment operator whose + first parameter is a reference to const qualified T. + 2 if D is a copy constructor or copy assignment operator whose + first parameter is a reference to non-const qualified T. + + This function can be used as a predicate. Positive values indicate + a copy constructor and non-zero values indicate a copy assignment + operator. */ int -copy_args_p (d) +copy_fn_p (d) tree d; { - tree t = FUNCTION_ARG_CHAIN (d); - if (DECL_CONSTRUCTOR_P (d) - && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (d))) - { - t = TREE_CHAIN (t); - if (TYPE_USES_PVBASES (DECL_CONTEXT (d))) - t = TREE_CHAIN (t); + tree args; + tree arg_type; + int result = 1; + + my_friendly_assert (DECL_FUNCTION_MEMBER_P (d), 20011208); + + if (DECL_TEMPLATE_INFO (d) && is_member_template (DECL_TI_TEMPLATE (d))) + /* Instantiations of template member functions are never copy + functions. Note that member functions of templated classes are + represented as template functions internally, and we must + accept those as copy functions. */ + return 0; + + args = FUNCTION_FIRST_USER_PARMTYPE (d); + if (!args) + return 0; + + arg_type = TREE_VALUE (args); + + if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d)) + { + /* Pass by value copy assignment operator. */ + result = -1; + } + else if (TREE_CODE (arg_type) == REFERENCE_TYPE + && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d)) + { + if (CP_TYPE_CONST_P (TREE_TYPE (arg_type))) + result = 2; } + else + return 0; - if (t && TREE_CODE (TREE_VALUE (t)) == REFERENCE_TYPE - && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (t))) - == DECL_CLASS_CONTEXT (d)) - && (TREE_CHAIN (t) == NULL_TREE - || TREE_CHAIN (t) == void_list_node - || TREE_PURPOSE (TREE_CHAIN (t)))) - return 1; - return 0; + args = TREE_CHAIN (args); + + if (args && args != void_list_node && !TREE_PURPOSE (args)) + /* There are more non-optional args. */ + return 0; + + return result; +} + +/* Remember any special properties of member function DECL. */ + +void grok_special_member_properties (decl) + tree decl; +{ + if (!DECL_NONSTATIC_MEMBER_FUNCTION_P(decl)) + ; /* Not special. */ + else if (DECL_CONSTRUCTOR_P (decl)) + { + int ctor = copy_fn_p (decl); + + if (ctor > 0) + { + /* [class.copy] + + A non-template constructor for class X is a copy + constructor if its first parameter is of type X&, const + X&, volatile X& or const volatile X&, and either there + are no other parameters or else all other parameters have + default arguments. */ + TYPE_HAS_INIT_REF (DECL_CONTEXT (decl)) = 1; + if (ctor > 1) + TYPE_HAS_CONST_INIT_REF (DECL_CONTEXT (decl)) = 1; + } + else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl))) + TYPE_HAS_DEFAULT_CONSTRUCTOR (DECL_CONTEXT (decl)) = 1; + } + else if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR) + { + /* [class.copy] + + A non-template assignment operator for class X is a copy + assignment operator if its parameter is of type X, X&, const + X&, volatile X& or const volatile X&. */ + + int assop = copy_fn_p (decl); + + if (assop) + { + TYPE_HAS_ASSIGN_REF (DECL_CONTEXT (decl)) = 1; + if (assop != 1) + TYPE_HAS_CONST_ASSIGN_REF (DECL_CONTEXT (decl)) = 1; + if (DECL_PURE_VIRTUAL_P (decl)) + TYPE_HAS_ABSTRACT_ASSIGN_REF (DECL_CONTEXT (decl)) = 1; + } + } } -/* These memoizing functions keep track of special properties which - a class may have. `grok_ctor_properties' notices whether a class - has a constructor of the form X(X&), and also complains - if the class has a constructor of the form X(X). - `grok_op_properties' takes notice of the various forms of - operator= which are defined, as well as what sorts of type conversion - may apply. Both functions take a FUNCTION_DECL as an argument. */ +/* Check a constructor DECL has the correct form. Complains + if the class has a constructor of the form X(X). */ int grok_ctor_properties (ctype, decl) tree ctype, decl; { - tree parmtypes = FUNCTION_ARG_CHAIN (decl); - tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; - - /* When a type has virtual baseclasses, a magical first int argument is - added to any ctor so we can tell if the class has been initialized - yet. This could screw things up in this function, so we deliberately - ignore the leading int if we're in that situation. */ - if (TYPE_USES_VIRTUAL_BASECLASSES (ctype) - && !CLASSTYPE_IS_TEMPLATE (ctype)) - { - my_friendly_assert (parmtypes - && TREE_VALUE (parmtypes) == integer_type_node, - 980529); - parmtypes = TREE_CHAIN (parmtypes); - parmtype = TREE_VALUE (parmtypes); - } - - if (TYPE_USES_PVBASES (ctype)) - { - my_friendly_assert (parmtypes - && TREE_VALUE (parmtypes) == vlist_type_node, - 980529); - parmtypes = TREE_CHAIN (parmtypes); - parmtype = TREE_VALUE (parmtypes); - } - - maybe_vlist_ctor_wrapper (decl, 0); - - /* [class.copy] - - A non-template constructor for class X is a copy constructor if - its first parameter is of type X&, const X&, volatile X& or const - volatile X&, and either there are no other parameters or else all - other parameters have default arguments. */ - if (TREE_CODE (parmtype) == REFERENCE_TYPE - && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype - && (TREE_CHAIN (parmtypes) == NULL_TREE - || TREE_CHAIN (parmtypes) == void_list_node - || TREE_PURPOSE (TREE_CHAIN (parmtypes))) - && !(DECL_TEMPLATE_INSTANTIATION (decl) - && is_member_template (DECL_TI_TEMPLATE (decl)))) - { - TYPE_HAS_INIT_REF (ctype) = 1; - if (CP_TYPE_CONST_P (TREE_TYPE (parmtype))) - TYPE_HAS_CONST_INIT_REF (ctype) = 1; - } - /* [class.copy] - - A declaration of a constructor for a class X is ill-formed if its - first parameter is of type (optionally cv-qualified) X and either - there are no other parameters or else all other parameters have - default arguments. - - We *don't* complain about member template instantiations that - have this form, though; they can occur as we try to decide what - constructor to use during overload resolution. Since overload - resolution will never prefer such a constructor to the - non-template copy constructor (which is either explicitly or - implicitly defined), there's no need to worry about their - existence. Theoretically, they should never even be - instantiated, but that's hard to forestall. */ - else if (TYPE_MAIN_VARIANT (parmtype) == ctype - && (TREE_CHAIN (parmtypes) == NULL_TREE - || TREE_CHAIN (parmtypes) == void_list_node - || TREE_PURPOSE (TREE_CHAIN (parmtypes))) - && !(DECL_TEMPLATE_INSTANTIATION (decl) - && is_member_template (DECL_TI_TEMPLATE (decl)))) - { - cp_error ("invalid constructor; you probably meant `%T (const %T&)'", + int ctor_parm = copy_fn_p (decl); + + if (ctor_parm < 0) + { + /* [class.copy] + + A declaration of a constructor for a class X is ill-formed if + its first parameter is of type (optionally cv-qualified) X + and either there are no other parameters or else all other + parameters have default arguments. + + We *don't* complain about member template instantiations that + have this form, though; they can occur as we try to decide + what constructor to use during overload resolution. Since + overload resolution will never prefer such a constructor to + the non-template copy constructor (which is either explicitly + or implicitly defined), there's no need to worry about their + existence. Theoretically, they should never even be + instantiated, but that's hard to forestall. */ + error ("invalid constructor; you probably meant `%T (const %T&)'", ctype, ctype); SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); return 0; } - else if (TREE_CODE (parmtype) == VOID_TYPE - || TREE_PURPOSE (parmtypes) != NULL_TREE) - TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; - + return 1; } -/* An operator with this name can be either unary or binary. */ +/* An operator with this code is unary, but can also be binary. */ static int -ambi_op_p (name) - tree name; +ambi_op_p (code) + enum tree_code code; { - return (name == ansi_opname [(int) INDIRECT_REF] - || name == ansi_opname [(int) ADDR_EXPR] - || name == ansi_opname [(int) NEGATE_EXPR] - || name == ansi_opname[(int) POSTINCREMENT_EXPR] - || name == ansi_opname[(int) POSTDECREMENT_EXPR] - || name == ansi_opname [(int) CONVERT_EXPR]); + return (code == INDIRECT_REF + || code == ADDR_EXPR + || code == CONVERT_EXPR + || code == NEGATE_EXPR + || code == PREINCREMENT_EXPR + || code == PREDECREMENT_EXPR); } /* An operator with this name can only be unary. */ static int -unary_op_p (name) - tree name; +unary_op_p (code) + enum tree_code code; { - return (name == ansi_opname [(int) TRUTH_NOT_EXPR] - || name == ansi_opname [(int) BIT_NOT_EXPR] - || name == ansi_opname [(int) COMPONENT_REF] - || IDENTIFIER_TYPENAME_P (name)); + return (code == TRUTH_NOT_EXPR + || code == BIT_NOT_EXPR + || code == COMPONENT_REF + || code == TYPE_EXPR); } /* Do a little sanity-checking on how they declared their operator. */ void -grok_op_properties (decl, virtualp, friendp) +grok_op_properties (decl, friendp) tree decl; - int virtualp, friendp; + int friendp; { tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); + tree argtype; int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); tree name = DECL_NAME (decl); + enum tree_code operator_code; + int arity; + + /* Count the number of arguments. */ + for (argtype = argtypes, arity = 0; + argtype && argtype != void_list_node; + argtype = TREE_CHAIN (argtype)) + ++arity; if (current_class_type == NULL_TREE) friendp = 1; + if (DECL_CONV_FN_P (decl)) + operator_code = TYPE_EXPR; + else + do + { +#define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \ + if (ansi_opname (CODE) == name) \ + { \ + operator_code = (CODE); \ + break; \ + } \ + else if (ansi_assopname (CODE) == name) \ + { \ + operator_code = (CODE); \ + DECL_ASSIGNMENT_OPERATOR_P (decl) = 1; \ + break; \ + } + +#include "operators.def" +#undef DEF_OPERATOR + + abort (); + } + while (0); + my_friendly_assert (operator_code != LAST_CPLUS_TREE_CODE, 20000526); + SET_OVERLOADED_OPERATOR_CODE (decl, operator_code); + if (! friendp) { - /* [class.copy] + switch (operator_code) + { + case CALL_EXPR: + TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1; + break; - A user-declared copy assignment operator X::operator= is a - non-static non-template member function of class X with - exactly one parameter of type X, X&, const X&, volatile X& or - const volatile X&. */ - if (name == ansi_opname[(int) MODIFY_EXPR] - && !(DECL_TEMPLATE_INSTANTIATION (decl) - && is_member_template (DECL_TI_TEMPLATE (decl)))) - ; - else if (name == ansi_opname[(int) CALL_EXPR]) - TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1; - else if (name == ansi_opname[(int) ARRAY_REF]) - TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1; - else if (name == ansi_opname[(int) COMPONENT_REF] - || name == ansi_opname[(int) MEMBER_REF]) - TYPE_OVERLOADS_ARROW (current_class_type) = 1; - else if (name == ansi_opname[(int) NEW_EXPR]) - TYPE_GETS_NEW (current_class_type) |= 1; - else if (name == ansi_opname[(int) DELETE_EXPR]) - TYPE_GETS_DELETE (current_class_type) |= 1; - else if (name == ansi_opname[(int) VEC_NEW_EXPR]) - TYPE_GETS_NEW (current_class_type) |= 2; - else if (name == ansi_opname[(int) VEC_DELETE_EXPR]) - TYPE_GETS_DELETE (current_class_type) |= 2; - } - - if (name == ansi_opname[(int) NEW_EXPR] - || name == ansi_opname[(int) VEC_NEW_EXPR]) + case ARRAY_REF: + TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1; + break; + + case COMPONENT_REF: + case MEMBER_REF: + TYPE_OVERLOADS_ARROW (current_class_type) = 1; + break; + + case NEW_EXPR: + TYPE_HAS_NEW_OPERATOR (current_class_type) = 1; + break; + + case DELETE_EXPR: + TYPE_GETS_DELETE (current_class_type) |= 1; + break; + + case VEC_NEW_EXPR: + TYPE_HAS_ARRAY_NEW_OPERATOR (current_class_type) = 1; + break; + + case VEC_DELETE_EXPR: + TYPE_GETS_DELETE (current_class_type) |= 2; + break; + + default: + break; + } + } + + if (operator_code == NEW_EXPR || operator_code == VEC_NEW_EXPR) { /* When the compiler encounters the definition of A::operator new, it doesn't look at the class declaration to find out if it's static. */ if (methodp) - revert_static_member_fn (&decl, NULL, NULL); - - /* Take care of function decl if we had syntax errors. */ - if (argtypes == NULL_TREE) - TREE_TYPE (decl) - = build_function_type (ptr_type_node, - hash_tree_chain (integer_type_node, - void_list_node)); - else - TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); + revert_static_member_fn (decl); + + TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); } - else if (name == ansi_opname[(int) DELETE_EXPR] - || name == ansi_opname[(int) VEC_DELETE_EXPR]) + else if (operator_code == DELETE_EXPR || operator_code == VEC_DELETE_EXPR) { if (methodp) - revert_static_member_fn (&decl, NULL, NULL); - - if (argtypes == NULL_TREE) - TREE_TYPE (decl) - = build_function_type (void_type_node, - hash_tree_chain (ptr_type_node, - void_list_node)); - else - { - TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); + revert_static_member_fn (decl); - if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR] - && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))) - != void_list_node)) - TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1; - } + TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); } else { @@ -12344,18 +12398,18 @@ grok_op_properties (decl, virtualp, friendp) an enumeration, or a reference to an enumeration. 13.4.0.6 */ if (! methodp || DECL_STATIC_FUNCTION_P (decl)) { - if (IDENTIFIER_TYPENAME_P (name) - || name == ansi_opname[(int) CALL_EXPR] - || name == ansi_opname[(int) MODIFY_EXPR] - || name == ansi_opname[(int) COMPONENT_REF] - || name == ansi_opname[(int) ARRAY_REF]) - cp_error ("`%D' must be a nonstatic member function", decl); + if (operator_code == TYPE_EXPR + || operator_code == CALL_EXPR + || operator_code == COMPONENT_REF + || operator_code == ARRAY_REF + || operator_code == NOP_EXPR) + error ("`%D' must be a nonstatic member function", decl); else { tree p = argtypes; if (DECL_STATIC_FUNCTION_P (decl)) - cp_error ("`%D' must be either a non-static member function or a non-member function", decl); + error ("`%D' must be either a non-static member function or a non-member function", decl); if (p) for (; TREE_CODE (TREE_VALUE (p)) != VOID_TYPE ; p = TREE_CHAIN (p)) @@ -12368,37 +12422,38 @@ grok_op_properties (decl, virtualp, friendp) if (IS_AGGR_TYPE (arg) || TREE_CODE (arg) == ENUMERAL_TYPE || TREE_CODE (arg) == TEMPLATE_TYPE_PARM - || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM) + || TREE_CODE (arg) == BOUND_TEMPLATE_TEMPLATE_PARM) goto foundaggr; } - cp_error + error ("`%D' must have an argument of class or enumerated type", decl); foundaggr: ; } } - - if (name == ansi_opname[(int) CALL_EXPR]) + + if (operator_code == CALL_EXPR) return; /* No restrictions on args. */ if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl)) { tree t = TREE_TYPE (name); - if (TREE_CODE (t) == VOID_TYPE) - pedwarn ("void is not a valid type conversion operator"); - else if (! friendp) + if (! friendp) { int ref = (TREE_CODE (t) == REFERENCE_TYPE); const char *what = 0; + if (ref) t = TYPE_MAIN_VARIANT (TREE_TYPE (t)); - if (t == current_class_type) + if (TREE_CODE (t) == VOID_TYPE) + what = "void"; + else if (t == current_class_type) what = "the same type"; /* Don't force t to be complete here. */ else if (IS_AGGR_TYPE (t) - && TYPE_SIZE (t) + && COMPLETE_TYPE_P (t) && DERIVED_FROM_P (t, current_class_type)) what = "a base class"; @@ -12407,50 +12462,63 @@ grok_op_properties (decl, virtualp, friendp) ref ? "a reference to " : "", what); } } - - if (name == ansi_opname[(int) MODIFY_EXPR]) + if (operator_code == COND_EXPR) { - tree parmtype; - - if (list_length (argtypes) != 3 && methodp) - { - cp_error ("`%D' must take exactly one argument", decl); - return; - } - parmtype = TREE_VALUE (TREE_CHAIN (argtypes)); - - if (copy_assignment_arg_p (parmtype, virtualp) - && ! friendp) - { - TYPE_HAS_ASSIGN_REF (current_class_type) = 1; - if (TREE_CODE (parmtype) != REFERENCE_TYPE - || CP_TYPE_CONST_P (TREE_TYPE (parmtype))) - TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1; - } + /* 13.4.0.3 */ + error ("ISO C++ prohibits overloading operator ?:"); } - else if (name == ansi_opname[(int) COND_EXPR]) + else if (ambi_op_p (operator_code)) { - /* 13.4.0.3 */ - pedwarn ("ANSI C++ prohibits overloading operator ?:"); - if (list_length (argtypes) != 4) - cp_error ("`%D' must take exactly three arguments", decl); - } - else if (ambi_op_p (name)) - { - if (list_length (argtypes) == 2) - /* prefix */; - else if (list_length (argtypes) == 3) + if (arity == 1) + /* We pick the one-argument operator codes by default, so + we don't have to change anything. */ + ; + else if (arity == 2) { - if ((name == ansi_opname[(int) POSTINCREMENT_EXPR] - || name == ansi_opname[(int) POSTDECREMENT_EXPR]) + /* If we thought this was a unary operator, we now know + it to be a binary operator. */ + switch (operator_code) + { + case INDIRECT_REF: + operator_code = MULT_EXPR; + break; + + case ADDR_EXPR: + operator_code = BIT_AND_EXPR; + break; + + case CONVERT_EXPR: + operator_code = PLUS_EXPR; + break; + + case NEGATE_EXPR: + operator_code = MINUS_EXPR; + break; + + case PREINCREMENT_EXPR: + operator_code = POSTINCREMENT_EXPR; + break; + + case PREDECREMENT_EXPR: + operator_code = POSTDECREMENT_EXPR; + break; + + default: + abort (); + } + + SET_OVERLOADED_OPERATOR_CODE (decl, operator_code); + + if ((operator_code == POSTINCREMENT_EXPR + || operator_code == POSTDECREMENT_EXPR) && ! processing_template_decl && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)), integer_type_node)) { if (methodp) - cp_error ("postfix `%D' must take `int' as its argument", + error ("postfix `%D' must take `int' as its argument", decl); else - cp_error + error ("postfix `%D' must take `int' as its second argument", decl); } @@ -12458,90 +12526,94 @@ grok_op_properties (decl, virtualp, friendp) else { if (methodp) - cp_error ("`%D' must take either zero or one argument", decl); + error ("`%D' must take either zero or one argument", decl); else - cp_error ("`%D' must take either one or two arguments", decl); + error ("`%D' must take either one or two arguments", decl); } /* More Effective C++ rule 6. */ if (warn_ecpp - && (name == ansi_opname[(int) POSTINCREMENT_EXPR] - || name == ansi_opname[(int) POSTDECREMENT_EXPR])) + && (operator_code == POSTINCREMENT_EXPR + || operator_code == POSTDECREMENT_EXPR + || operator_code == PREINCREMENT_EXPR + || operator_code == PREDECREMENT_EXPR)) { tree arg = TREE_VALUE (argtypes); tree ret = TREE_TYPE (TREE_TYPE (decl)); if (methodp || TREE_CODE (arg) == REFERENCE_TYPE) arg = TREE_TYPE (arg); arg = TYPE_MAIN_VARIANT (arg); - if (list_length (argtypes) == 2) + if (operator_code == PREINCREMENT_EXPR + || operator_code == PREDECREMENT_EXPR) { if (TREE_CODE (ret) != REFERENCE_TYPE || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg)) - cp_warning ("prefix `%D' should return `%T'", decl, + warning ("prefix `%D' should return `%T'", decl, build_reference_type (arg)); } else { if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg)) - cp_warning ("postfix `%D' should return `%T'", decl, arg); + warning ("postfix `%D' should return `%T'", decl, arg); } } } - else if (unary_op_p (name)) + else if (unary_op_p (operator_code)) { - if (list_length (argtypes) != 2) + if (arity != 1) { if (methodp) - cp_error ("`%D' must take `void'", decl); + error ("`%D' must take `void'", decl); else - cp_error ("`%D' must take exactly one argument", decl); + error ("`%D' must take exactly one argument", decl); } } - else /* if (binary_op_p (name)) */ + else /* if (binary_op_p (operator_code)) */ { - if (list_length (argtypes) != 3) + if (arity != 2) { if (methodp) - cp_error ("`%D' must take exactly one argument", decl); + error ("`%D' must take exactly one argument", decl); else - cp_error ("`%D' must take exactly two arguments", decl); + error ("`%D' must take exactly two arguments", decl); } /* More Effective C++ rule 7. */ if (warn_ecpp - && (name == ansi_opname [TRUTH_ANDIF_EXPR] - || name == ansi_opname [TRUTH_ORIF_EXPR] - || name == ansi_opname [COMPOUND_EXPR])) - cp_warning ("user-defined `%D' always evaluates both arguments", + && (operator_code == TRUTH_ANDIF_EXPR + || operator_code == TRUTH_ORIF_EXPR + || operator_code == COMPOUND_EXPR)) + warning ("user-defined `%D' always evaluates both arguments", decl); } /* Effective C++ rule 23. */ if (warn_ecpp - && list_length (argtypes) == 3 - && (name == ansi_opname [PLUS_EXPR] - || name == ansi_opname [MINUS_EXPR] - || name == ansi_opname [TRUNC_DIV_EXPR] - || name == ansi_opname [MULT_EXPR]) + && arity == 2 + && (operator_code == PLUS_EXPR + || operator_code == MINUS_EXPR + || operator_code == TRUNC_DIV_EXPR + || operator_code == MULT_EXPR) && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE) - cp_warning ("`%D' should return by value", decl); + warning ("`%D' should return by value", decl); + + /* [over.oper]/8 */ + for (; argtypes && argtypes != void_list_node; + argtypes = TREE_CHAIN (argtypes)) + if (TREE_PURPOSE (argtypes)) + { + TREE_PURPOSE (argtypes) = NULL_TREE; + if (operator_code == POSTINCREMENT_EXPR + || operator_code == POSTDECREMENT_EXPR) + { + if (pedantic) + pedwarn ("`%D' cannot have default arguments", decl); + } + else + error ("`%D' cannot have default arguments", decl); + } - /* 13.4.0.8 */ - if (argtypes) - for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes)) - if (TREE_PURPOSE (argtypes)) - { - TREE_PURPOSE (argtypes) = NULL_TREE; - if (name == ansi_opname[(int) POSTINCREMENT_EXPR] - || name == ansi_opname[(int) POSTDECREMENT_EXPR]) - { - if (pedantic) - cp_pedwarn ("`%D' cannot have default arguments", decl); - } - else - cp_error ("`%D' cannot have default arguments", decl); - } } } @@ -12559,10 +12631,8 @@ tag_name (code) return "union "; case enum_type: return "enum"; - case signature_type: - return "signature"; default: - my_friendly_abort (981122); + abort (); } } @@ -12584,7 +12654,6 @@ xref_tag (code_type_node, name, globalize) { enum tag_types tag_code; enum tree_code code; - int temp = 0; register tree ref, t; struct binding_level *b = current_binding_level; int got_type = 0; @@ -12601,12 +12670,11 @@ xref_tag (code_type_node, name, globalize) code_type_node = TREE_VALUE (code_type_node); } - tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); + tag_code = (enum tag_types) tree_low_cst (code_type_node, 1); switch (tag_code) { case record_type: case class_type: - case signature_type: code = RECORD_TYPE; break; case union_type: @@ -12616,12 +12684,12 @@ xref_tag (code_type_node, name, globalize) code = ENUMERAL_TYPE; break; default: - my_friendly_abort (18); + abort (); } /* If a cross reference is requested, look up the type already defined for this tag and return it. */ - if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') + if (TYPE_P (name)) { t = name; name = TYPE_IDENTIFIER (t); @@ -12630,8 +12698,34 @@ xref_tag (code_type_node, name, globalize) else t = IDENTIFIER_TYPE_VALUE (name); + /* Warn about 'friend struct Inherited;' doing the wrong thing. */ + if (t && globalize && TREE_CODE (t) == TYPENAME_TYPE) + { + static int explained; + tree shadowed; + + warning ("`%s %T' declares a new type at namespace scope", + tag_name (tag_code), name); + if (!explained++) + warning (" names from dependent base classes are not visible to unqualified name lookup - to refer to the inherited type, say `%s %T::%T'", + tag_name (tag_code), + constructor_name (current_class_type), + TYPE_IDENTIFIER (t)); + + /* We need to remove the class scope binding for the + TYPENAME_TYPE as otherwise poplevel_class gets confused. */ + for (shadowed = b->class_shadowed; + shadowed; + shadowed = TREE_CHAIN (shadowed)) + if (TREE_TYPE (shadowed) == TYPE_NAME (t)) + { + TREE_PURPOSE (shadowed) = NULL_TREE; + break; + } + } + if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM - && TREE_CODE (t) != TEMPLATE_TEMPLATE_PARM) + && TREE_CODE (t) != BOUND_TEMPLATE_TEMPLATE_PARM) t = NULL_TREE; if (! globalize) @@ -12649,21 +12743,21 @@ xref_tag (code_type_node, name, globalize) elaborated-type-specifier is ill-formed. */ if (t != TYPE_MAIN_VARIANT (t) || (CLASS_TYPE_P (t) && TYPE_WAS_ANONYMOUS (t))) - cp_pedwarn ("using typedef-name `%D' after `%s'", + pedwarn ("using typedef-name `%D' after `%s'", TYPE_NAME (t), tag_name (tag_code)); else if (TREE_CODE (t) == TEMPLATE_TYPE_PARM) - cp_error ("using template type parameter `%T' after `%s'", + error ("using template type parameter `%T' after `%s'", t, tag_name (tag_code)); ref = t; } else ref = lookup_tag (code, name, b, 0); - + if (! ref) { /* Try finding it as a type declaration. If that wins, - use it. */ + use it. */ ref = lookup_name (name, 1); if (ref != NULL_TREE @@ -12672,7 +12766,7 @@ xref_tag (code_type_node, name, globalize) && template_class_depth (current_class_type) == 0) /* Since GLOBALIZE is true, we're declaring a global template, so we want this type. */ - ref = DECL_RESULT (ref); + ref = DECL_TEMPLATE_RESULT (ref); if (ref && TREE_CODE (ref) == TYPE_DECL && TREE_CODE (TREE_TYPE (ref)) == code) @@ -12681,9 +12775,9 @@ xref_tag (code_type_node, name, globalize) ref = NULL_TREE; } - if (ref && current_class_type - && template_class_depth (current_class_type) - && PROCESSING_REAL_TEMPLATE_DECL_P ()) + if (ref && current_class_type + && template_class_depth (current_class_type) + && PROCESSING_REAL_TEMPLATE_DECL_P ()) { /* Since GLOBALIZE is non-zero, we are not looking at a definition of this tag. Since, in addition, we are currently @@ -12726,25 +12820,15 @@ xref_tag (code_type_node, name, globalize) } } - push_obstacks_nochange (); - if (! ref) { /* If no such tag is yet defined, create a forward-reference node and record it as the "definition". When a real declaration of this type is found, the forward-reference will be altered into a real type. */ - - /* In C++, since these migrate into the global scope, we must - build them on the permanent obstack. */ - - temp = allocation_temporary_p (); - if (temp) - end_temporary_allocation (); - if (code == ENUMERAL_TYPE) { - cp_error ("use of enum `%#D' without previous declaration", name); + error ("use of enum `%#D' without previous declaration", name); ref = make_node (ENUMERAL_TYPE); @@ -12752,6 +12836,7 @@ xref_tag (code_type_node, name, globalize) to avoid crashing if it does not get defined. */ TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); + TYPE_USER_ALIGN (ref) = 0; TREE_UNSIGNED (ref) = 1; TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); @@ -12768,20 +12853,9 @@ xref_tag (code_type_node, name, globalize) { struct binding_level *old_b = class_binding_level; - ref = make_lang_type (code); + ref = make_aggr_type (code); TYPE_CONTEXT (ref) = context; - if (tag_code == signature_type) - { - SET_SIGNATURE (ref); - /* Since a signature type will be turned into the type - of signature tables, it's not only an interface. */ - CLASSTYPE_INTERFACE_ONLY (ref) = 0; - SET_CLASSTYPE_INTERFACE_KNOWN (ref); - /* A signature doesn't have a vtable. */ - CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0; - } - #ifdef NONNESTED_CLASSES /* Class types don't nest the way enums do. */ class_binding_level = (struct binding_level *)0; @@ -12792,36 +12866,24 @@ xref_tag (code_type_node, name, globalize) } else { - /* If it no longer looks like a nested type, make sure it's - in global scope. - If it is not an IDENTIFIER, this is not a declaration */ - if (b->namespace_p && !class_binding_level - && TREE_CODE (name) == IDENTIFIER_NODE) - { - if (IDENTIFIER_NAMESPACE_VALUE (name) == NULL_TREE) - SET_IDENTIFIER_NAMESPACE_VALUE (name, TYPE_NAME (ref)); - } - if (!globalize && processing_template_decl && IS_AGGR_TYPE (ref)) redeclare_class_template (ref, current_template_parms); } /* Until the type is defined, tentatively accept whatever structure tag the user hands us. */ - if (TYPE_SIZE (ref) == NULL_TREE + if (!COMPLETE_TYPE_P (ref) && ref != current_class_type /* Have to check this, in case we have contradictory tag info. */ && IS_AGGR_TYPE_CODE (TREE_CODE (ref))) { if (tag_code == class_type) CLASSTYPE_DECLARED_CLASS (ref) = 1; - else if (tag_code == record_type || tag_code == signature_type) + else if (tag_code == record_type) CLASSTYPE_DECLARED_CLASS (ref) = 0; } - pop_obstacks (); - - TREE_TYPE (ref) = attributes; + TYPE_ATTRIBUTES (ref) = attributes; return ref; } @@ -12863,16 +12925,24 @@ xref_basetypes (code_type_node, name, ref, binfo) tree base; int i, len; - enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); + enum tag_types tag_code; + + /* If we are called from the parser, code_type_node will sometimes be a + TREE_LIST. This indicates that the user wrote + "class __attribute__ ((foo)) bar". Extract the attributes so that + tree_low_cst doesn't crash. */ + if (TREE_CODE (code_type_node) == TREE_LIST) + code_type_node = TREE_VALUE (code_type_node); + + tag_code = (enum tag_types) tree_low_cst (code_type_node, 1); if (tag_code == union_type) { - cp_error ("derived union `%T' invalid", ref); + error ("derived union `%T' invalid", ref); return; } len = list_length (binfo); - push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref)); /* First, make sure that any templates in base-classes are instantiated. This ensures that if we call ourselves recursively @@ -12910,9 +12980,9 @@ xref_basetypes (code_type_node, name, ref, binfo) || (TREE_CODE (basetype) != RECORD_TYPE && TREE_CODE (basetype) != TYPENAME_TYPE && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM - && TREE_CODE (basetype) != TEMPLATE_TEMPLATE_PARM)) + && TREE_CODE (basetype) != BOUND_TEMPLATE_TEMPLATE_PARM)) { - cp_error ("base type `%T' fails to be a struct or class type", + error ("base type `%T' fails to be a struct or class type", TREE_VALUE (binfo)); continue; } @@ -12921,10 +12991,10 @@ xref_basetypes (code_type_node, name, ref, binfo) /* This code replaces similar code in layout_basetypes. We put the complete_type first for implicit `typename'. */ - if (TYPE_SIZE (basetype) == NULL_TREE + if (!COMPLETE_TYPE_P (basetype) && ! (current_template_parms && uses_template_parms (basetype))) { - cp_error ("base class `%T' has incomplete type", basetype); + error ("base class `%T' has incomplete type", basetype); continue; } else @@ -12932,14 +13002,14 @@ xref_basetypes (code_type_node, name, ref, binfo) if (CLASSTYPE_MARKED (basetype)) { if (basetype == ref) - cp_error ("recursive type `%T' undefined", basetype); + error ("recursive type `%T' undefined", basetype); else - cp_error ("duplicate base type `%T' invalid", basetype); + error ("duplicate base type `%T' invalid", basetype); continue; } if (TYPE_FOR_JAVA (basetype) - && current_lang_stack == current_lang_base) + && (current_lang_depth () == 0)) TYPE_FOR_JAVA (ref) = 1; /* Note that the BINFO records which describe individual @@ -12949,14 +13019,14 @@ xref_basetypes (code_type_node, name, ref, binfo) derived classes. (Each BINFO record describing an individual inheritance contains flags which say what the `accessibility' of that particular inheritance is.) */ - - base_binfo - = make_binfo (integer_zero_node, basetype, + + base_binfo + = make_binfo (size_zero_node, basetype, CLASS_TYPE_P (basetype) ? TYPE_BINFO_VTABLE (basetype) : NULL_TREE, CLASS_TYPE_P (basetype) ? TYPE_BINFO_VIRTUALS (basetype) : NULL_TREE); - + TREE_VEC_ELT (binfos, i) = base_binfo; TREE_VIA_PUBLIC (base_binfo) = via_public; TREE_VIA_PROTECTED (base_binfo) = via_protected; @@ -12974,23 +13044,26 @@ xref_basetypes (code_type_node, name, ref, binfo) if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) { TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1; - TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; - /* The PVBASES flag is never set for templates; we know - only for instantiations whether the virtual bases are - polymorphic. */ - if (flag_vtable_thunks >= 2 && !CLASSTYPE_IS_TEMPLATE (ref)) - { - if (via_virtual && TYPE_VIRTUAL_P (basetype)) - TYPE_USES_PVBASES (ref) = 1; - else if (TYPE_USES_PVBASES (basetype)) - TYPE_USES_PVBASES (ref) = 1; - } + /* Converting to a virtual base class requires looking + up the offset of the virtual base. */ + TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (ref) = 1; } if (CLASS_TYPE_P (basetype)) { - TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype); + TYPE_HAS_NEW_OPERATOR (ref) + |= TYPE_HAS_NEW_OPERATOR (basetype); + TYPE_HAS_ARRAY_NEW_OPERATOR (ref) + |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype); TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype); + /* If the base-class uses multiple inheritance, so do we. */ + TYPE_USES_MULTIPLE_INHERITANCE (ref) + |= TYPE_USES_MULTIPLE_INHERITANCE (basetype); + /* Likewise, if converting to a base of the base may require + code, then we may need to generate code to convert to a + base as well. */ + TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (ref) + |= TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (basetype); } i += 1; @@ -13002,19 +13075,13 @@ xref_basetypes (code_type_node, name, ref, binfo) BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE; if (i > 1) - TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; - else if (i == 1) { - tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, 0)); - - if (CLASS_TYPE_P (basetype)) - TYPE_USES_MULTIPLE_INHERITANCE (ref) - = TYPE_USES_MULTIPLE_INHERITANCE (basetype); + TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; + /* If there is more than one non-empty they cannot be at the same + address. */ + TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (ref) = 1; } - if (TYPE_USES_MULTIPLE_INHERITANCE (ref)) - TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; - /* Unmark all the types. */ while (--i >= 0) CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i))); @@ -13022,11 +13089,9 @@ xref_basetypes (code_type_node, name, ref, binfo) /* Now that we know all the base-classes, set up the list of virtual bases. */ - CLASSTYPE_VBASECLASSES (ref) = get_vbase_types (ref); - - pop_obstacks (); + get_vbase_types (ref); } - + /* Begin compiling the definition of an enumeration type. NAME is its name (or null if anonymous). @@ -13041,10 +13106,6 @@ start_enum (name) register tree enumtype = NULL_TREE; struct binding_level *b = current_binding_level; - /* We are wasting space here and putting these on the permanent_obstack so - that typeid(local enum) will work correctly. */ - push_obstacks (&permanent_obstack, &permanent_obstack); - /* If this is the real definition for a previous forward reference, fill in the contents in the same object that used to be the forward reference. */ @@ -13053,7 +13114,12 @@ start_enum (name) enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE) - cp_error ("multiple definition of `%#T'", enumtype); + { + error ("multiple definition of `%#T'", enumtype); + cp_error_at ("previous definition here", enumtype); + /* Clear out TYPE_VALUES, and start again. */ + TYPE_VALUES (enumtype) = NULL_TREE; + } else { enumtype = make_node (ENUMERAL_TYPE); @@ -13063,259 +13129,311 @@ start_enum (name) if (current_class_type) TREE_ADDRESSABLE (b->tags) = 1; - /* We don't copy this value because build_enumerator needs to do it. */ - enum_next_value = integer_zero_node; - enum_overflow = 0; - GNU_xref_decl (current_function_decl, enumtype); return enumtype; } /* After processing and defining all the values of an enumeration type, install their decls in the enumeration type and finish it off. - ENUMTYPE is the type object and VALUES a list of name-value pairs. - Returns ENUMTYPE. */ + ENUMTYPE is the type object and VALUES a list of name-value pairs. */ -tree +void finish_enum (enumtype) tree enumtype; { - register tree minnode = NULL_TREE, maxnode = NULL_TREE; - /* Calculate the maximum value of any enumerator in this type. */ + tree pair; + tree minnode; + tree maxnode; + tree t; + bool unsignedp; + int lowprec; + int highprec; + int precision; + + /* We built up the VALUES in reverse order. */ + TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype)); + + /* [dcl.enum] + + Following the closing brace of an enum-specifier, each + enumerator has the type of its enumeration. Prior to the + closing brace, the type of each enumerator is the type of + its initializing value. */ + for (pair = TYPE_VALUES (enumtype); pair; pair = TREE_CHAIN (pair)) + TREE_TYPE (TREE_VALUE (pair)) = enumtype; + + /* For a enum defined in a template, all further processing is + postponed until the template is instantiated. */ + if (processing_template_decl) + { + tree scope = current_scope (); + if (scope && TREE_CODE (scope) == FUNCTION_DECL) + add_stmt (build_min (TAG_DEFN, enumtype)); + - tree values = TYPE_VALUES (enumtype); - if (values) + return; + } + + /* Figure out what the minimum and maximum values of the enumerators + are. */ + if (TYPE_VALUES (enumtype)) { - tree pair; + minnode = maxnode = NULL_TREE; - for (pair = values; pair; pair = TREE_CHAIN (pair)) + for (pair = TYPE_VALUES (enumtype); + pair; + pair = TREE_CHAIN (pair)) { - tree decl; tree value; - /* The TREE_VALUE is a CONST_DECL for this enumeration - constant. */ - decl = TREE_VALUE (pair); - - /* The DECL_INITIAL will be NULL if we are processing a - template declaration and this enumeration constant had no - explicit initializer. */ - value = DECL_INITIAL (decl); - if (value && !processing_template_decl) - { - /* Set the TREE_TYPE for the VALUE as well. That's so - that when we call decl_constant_value we get an - entity of the right type (but with the constant - value). Since we shouldn't ever call - decl_constant_value on a template type, there's no - reason to do that when processing_template_decl. - And, if the expression is something like a - TEMPLATE_PARM_INDEX or a CAST_EXPR doing so will - wreak havoc on the intended type of the expression. - - Of course, there's also no point in trying to compute - minimum or maximum values if we're in a template. */ - TREE_TYPE (value) = enumtype; - - if (!minnode) - minnode = maxnode = value; - else if (tree_int_cst_lt (maxnode, value)) - maxnode = value; - else if (tree_int_cst_lt (value, minnode)) - minnode = value; - } + value = DECL_INITIAL (TREE_VALUE (pair)); - if (processing_template_decl) - /* If this is just a template, leave the CONST_DECL - alone. That way tsubst_copy will find CONST_DECLs for - CONST_DECLs, and not INTEGER_CSTs. */ - ; - else - /* In the list we're building up, we want the enumeration - values, not the CONST_DECLs. */ - TREE_VALUE (pair) = value; + if (!minnode) + minnode = maxnode = value; + else if (tree_int_cst_lt (maxnode, value)) + maxnode = value; + else if (tree_int_cst_lt (value, minnode)) + minnode = value; } } else - maxnode = minnode = integer_zero_node; - - TYPE_VALUES (enumtype) = nreverse (values); - - if (processing_template_decl) - { - tree scope = current_scope (); - if (scope && TREE_CODE (scope) == FUNCTION_DECL) - add_tree (build_min (TAG_DEFN, enumtype)); - } + minnode = maxnode = integer_zero_node; + + /* Compute the number of bits require to represent all values of the + enumeration. We must do this before the type of MINNODE and + MAXNODE are transformed, since min_precision relies on the + TREE_TYPE of the value it is passed. */ + unsignedp = tree_int_cst_sgn (minnode) >= 0; + lowprec = min_precision (minnode, unsignedp); + highprec = min_precision (maxnode, unsignedp); + precision = MAX (lowprec, highprec); + + /* Set the TREE_TYPE for the values as well. That's so that when we + call decl_constant_value we get an entity of the right type (but + with the constant value). In addition, transform the TYPE_VALUES + list to contain the values, rather than the CONST_DECLs for them. */ + for (pair = TYPE_VALUES (enumtype); pair; pair = TREE_CHAIN (pair)) + { + tree value = DECL_INITIAL (TREE_VALUE (pair)); + + TREE_TYPE (value) = enumtype; + TREE_VALUE (pair) = value; + } + + /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */ + TYPE_SIZE (enumtype) = NULL_TREE; + TYPE_PRECISION (enumtype) = precision; + if (unsignedp) + fixup_unsigned_type (enumtype); else - { - int unsignedp = tree_int_cst_sgn (minnode) >= 0; - int lowprec = min_precision (minnode, unsignedp); - int highprec = min_precision (maxnode, unsignedp); - int precision = MAX (lowprec, highprec); - tree tem; - - TYPE_SIZE (enumtype) = NULL_TREE; + fixup_signed_type (enumtype); - /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */ - - TYPE_PRECISION (enumtype) = precision; - if (unsignedp) - fixup_unsigned_type (enumtype); - else - fixup_signed_type (enumtype); - - if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node))) - /* Use the width of the narrowest normal C type which is wide - enough. */ - TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size - (precision, 1)); - else - TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); + if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node))) + /* Use the width of the narrowest normal C type which is wide + enough. */ + TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size + (precision, 1)); + else + TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); - TYPE_SIZE (enumtype) = 0; - layout_type (enumtype); - - /* Fix up all variant types of this enum type. */ - for (tem = TYPE_MAIN_VARIANT (enumtype); tem; - tem = TYPE_NEXT_VARIANT (tem)) - { - TYPE_VALUES (tem) = TYPE_VALUES (enumtype); - TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); - TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); - TYPE_SIZE (tem) = TYPE_SIZE (enumtype); - TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype); - TYPE_MODE (tem) = TYPE_MODE (enumtype); - TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); - TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); - TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); - } + TYPE_SIZE (enumtype) = NULL_TREE; + layout_type (enumtype); - /* Finish debugging output for this type. */ - rest_of_type_compilation (enumtype, namespace_bindings_p ()); + /* Fix up all variant types of this enum type. */ + for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t)) + { + TYPE_VALUES (t) = TYPE_VALUES (enumtype); + TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (enumtype); + TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (enumtype); + TYPE_SIZE (t) = TYPE_SIZE (enumtype); + TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (enumtype); + TYPE_MODE (t) = TYPE_MODE (enumtype); + TYPE_PRECISION (t) = TYPE_PRECISION (enumtype); + TYPE_ALIGN (t) = TYPE_ALIGN (enumtype); + TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (enumtype); + TREE_UNSIGNED (t) = TREE_UNSIGNED (enumtype); } - /* In start_enum we pushed obstacks. Here, we must pop them. */ - pop_obstacks (); - - return enumtype; + /* Finish debugging output for this type. */ + rest_of_type_compilation (enumtype, namespace_bindings_p ()); } /* Build and install a CONST_DECL for an enumeration constant of the - enumeration type TYPE whose NAME and VALUE (if any) are provided. + enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided. Assignment of sequential values by default is handled here. */ -tree -build_enumerator (name, value, type) +void +build_enumerator (name, value, enumtype) tree name; tree value; - tree type; + tree enumtype; { - tree decl, result; + tree decl; tree context; + tree type; + tree values; /* Remove no-op casts from the value. */ if (value) STRIP_TYPE_NOPS (value); - if (! processing_template_decl) - { - /* Validate and default VALUE. */ - if (value != NULL_TREE) - { - if (TREE_READONLY_DECL_P (value)) - value = decl_constant_value (value); - - if (TREE_CODE (value) == INTEGER_CST) - { - value = default_conversion (value); - constant_expression_warning (value); - } - else - { - cp_error ("enumerator value for `%D' not integer constant", name); - value = NULL_TREE; - } - } - - /* Default based on previous value. */ - if (value == NULL_TREE && ! processing_template_decl) - { - value = enum_next_value; - if (enum_overflow) - cp_error ("overflow in enumeration values at `%D'", name); - } - - /* Remove no-op casts from the value. */ - if (value) - STRIP_TYPE_NOPS (value); + if (! processing_template_decl) + { + /* Validate and default VALUE. */ + if (value != NULL_TREE) + { + value = decl_constant_value (value); + + if (TREE_CODE (value) == INTEGER_CST) + { + value = default_conversion (value); + constant_expression_warning (value); + } + else + { + error ("enumerator value for `%D' not integer constant", name); + value = NULL_TREE; + } + } + + /* Default based on previous value. */ + if (value == NULL_TREE && ! processing_template_decl) + { + tree prev_value; + + if (TYPE_VALUES (enumtype)) + { + /* The next value is the previous value ... */ + prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype))); + /* ... plus one. */ + value = cp_build_binary_op (PLUS_EXPR, + prev_value, + integer_one_node); + + if (tree_int_cst_lt (value, prev_value)) + error ("overflow in enumeration values at `%D'", name); + } + else + value = integer_zero_node; + } + + /* Remove no-op casts from the value. */ + if (value) + STRIP_TYPE_NOPS (value); #if 0 - /* To fix MAX_VAL enum consts. (bkoz) */ - TREE_TYPE (value) = integer_type_node; + /* To fix MAX_VAL enum consts. (bkoz) */ + TREE_TYPE (value) = integer_type_node; #endif - } + } - /* We always have to copy here; not all INTEGER_CSTs are unshared. - Even in other cases, we will later (in finish_enum) be setting the - type of VALUE. */ - if (value != NULL_TREE) - value = copy_node (value); + /* We always have to copy here; not all INTEGER_CSTs are unshared. + Even in other cases, we will later (in finish_enum) be setting + the type of VALUE. But, we don't need to make a copy if this + VALUE is one of the enumeration constants for this same + enumeration type. */ + for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values)) + if (TREE_VALUE (values) == value) + break; + /* If we didn't break out of the loop, then we do need a copy. */ + if (!values && value) + value = copy_node (value); /* C++ associates enums with global, function, or class declarations. */ - - context = current_scope (); - if (context && context == current_class_type) - /* This enum declaration is local to the class. */ - decl = build_lang_field_decl (CONST_DECL, name, type); - else - /* It's a global enum, or it's local to a function. (Note local to + context = current_scope (); + + /* Build the actual enumeration constant. Note that the enumeration + constants have the type of their initializers until the + enumeration is complete: + + [ dcl.enum ] + + Following the closing brace of an enum-specifier, each enumer- + ator has the type of its enumeration. Prior to the closing + brace, the type of each enumerator is the type of its + initializing value. + + In finish_enum we will reset the type. Of course, if we're + processing a template, there may be no value. */ + type = value ? TREE_TYPE (value) : NULL_TREE; + + if (context && context == current_class_type) + /* This enum declaration is local to the class. We need the full + lang_decl so that we can record DECL_CLASS_CONTEXT, for example. */ + decl = build_lang_decl (CONST_DECL, name, type); + else + /* It's a global enum, or it's local to a function. (Note local to a function could mean local to a class method. */ - decl = build_decl (CONST_DECL, name, type); + decl = build_decl (CONST_DECL, name, type); - DECL_CONTEXT (decl) = FROB_CONTEXT (context); - DECL_INITIAL (decl) = value; - TREE_READONLY (decl) = 1; + DECL_CONTEXT (decl) = FROB_CONTEXT (context); + DECL_INITIAL (decl) = value; + TREE_READONLY (decl) = 1; - if (context && context == current_class_type) - /* In something like `struct S { enum E { i = 7 }; };' we put `i' + if (context && context == current_class_type) + /* In something like `struct S { enum E { i = 7 }; };' we put `i' on the TYPE_FIELDS list for `S'. (That's so that you can say things like `S::i' later.) */ - finish_member_declaration (decl); - else - { - pushdecl (decl); - GNU_xref_decl (current_function_decl, decl); - } - - if (! processing_template_decl) - { - /* Set basis for default for next value. */ - enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, - integer_one_node, PLUS_EXPR); - enum_overflow = tree_int_cst_lt (enum_next_value, value); - } - - result = saveable_tree_cons (name, decl, NULL_TREE); - return result; + finish_member_declaration (decl); + else + { + pushdecl (decl); + GNU_xref_decl (current_function_decl, decl); + } + + /* Add this enumeration constant to the list for this type. */ + TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype)); } -static int function_depth; +/* We're defining DECL. Make sure that it's type is OK. */ + +static void +check_function_type (decl, current_function_parms) + tree decl; + tree current_function_parms; +{ + tree fntype = TREE_TYPE (decl); + tree return_type = complete_type (TREE_TYPE (fntype)); + + /* In a function definition, arg types must be complete. */ + require_complete_types_for_parms (current_function_parms); + + if (!COMPLETE_OR_VOID_TYPE_P (return_type)) + { + error ("return type `%#T' is incomplete", TREE_TYPE (fntype)); + + /* Make it return void instead, but don't change the + type of the DECL_RESULT, in case we have a named return value. */ + if (TREE_CODE (fntype) == METHOD_TYPE) + { + tree ctype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))); + TREE_TYPE (decl) + = build_cplus_method_type (ctype, + void_type_node, + FUNCTION_ARG_CHAIN (decl)); + } + else + TREE_TYPE (decl) + = build_function_type (void_type_node, + TYPE_ARG_TYPES (TREE_TYPE (decl))); + TREE_TYPE (decl) + = build_exception_variant (fntype, + TYPE_RAISES_EXCEPTIONS (fntype)); + } + else + abstract_virtuals_error (decl, TREE_TYPE (fntype)); +} /* Create the FUNCTION_DECL for a function definition. DECLSPECS and DECLARATOR are the parts of the declaration; they describe the function's name and the type it returns, but twisted together in a fashion that parallels the syntax of C. - If PRE_PARSED_P is non-zero then DECLARATOR is really the DECL for - the function we are about to process; DECLSPECS are ignored. For - example, we set PRE_PARSED_P when processing the definition of - inline function that was defined in-class; the definition is - actually processed when the class is complete. In this case, - PRE_PARSED_P is 2. We also set PRE_PARSED_P when instanting the - body of a template function, and when constructing thunk functions - and such; in these cases PRE_PARSED_P is 1. - + FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the + DECLARATOR is really the DECL for the function we are about to + process and that DECLSPECS should be ignored), SF_INCLASS_INLINE + indicating that the function is an inline defined in-class. + This function creates a binding context for the function body as well as setting up the FUNCTION_DECL in current_function_decl. @@ -13326,16 +13444,12 @@ static int function_depth; For C++, we must first check whether that datum makes any sense. For example, "class A local_a(1,2);" means that variable local_a is an aggregate of type A, which should have a constructor - applied to it with the argument list [1, 2]. - - @@ There is currently no way to retrieve the storage - @@ allocated to FUNCTION (or all of its parms) if we return - @@ something we had previously. */ + applied to it with the argument list [1, 2]. */ int -start_function (declspecs, declarator, attrs, pre_parsed_p) +start_function (declspecs, declarator, attrs, flags) tree declspecs, declarator, attrs; - int pre_parsed_p; + int flags; { tree decl1; tree ctype = NULL_TREE; @@ -13344,68 +13458,33 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) extern int have_extern_spec; extern int used_extern_spec; int doing_friend = 0; + struct binding_level *bl; + tree current_function_parms; /* Sanity check. */ my_friendly_assert (TREE_CODE (TREE_VALUE (void_list_node)) == VOID_TYPE, 160); my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); - /* Assume, until we see it does. */ - current_function_returns_value = 0; - current_function_returns_null = 0; - named_labels = 0; - shadowed_labels = 0; - current_function_assigns_this = 0; - current_function_just_assigned_this = 0; - current_function_parms_stored = 0; - original_result_rtx = NULL_RTX; - base_init_expr = NULL_TREE; - current_base_init_list = NULL_TREE; - current_member_init_list = NULL_TREE; - ctor_label = dtor_label = NULL_TREE; - static_labelno = 0; - - clear_temp_name (); - /* This should only be done once on the top most decl. */ if (have_extern_spec && !used_extern_spec) { - declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); + declspecs = tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); used_extern_spec = 1; } - if (pre_parsed_p) + if (flags & SF_PRE_PARSED) { decl1 = declarator; -#if 0 - /* What was this testing for, exactly? */ - if (! DECL_ARGUMENTS (decl1) - && !DECL_STATIC_FUNCTION_P (decl1) - && !DECL_ARTIFICIAL (decl1) - && DECL_CLASS_SCOPE_P (decl1) - && TYPE_IDENTIFIER (DECL_CONTEXT (decl1)) - && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (DECL_CONTEXT (decl1)))) - { - tree binding = binding_for_name (DECL_NAME (decl1), - current_namespace); - cp_error ("redeclaration of `%#D'", decl1); - if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))) - cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))); - else if (BINDING_VALUE (binding)) - cp_error_at ("previous declaration here", BINDING_VALUE (binding)); - } -#endif - fntype = TREE_TYPE (decl1); if (TREE_CODE (fntype) == METHOD_TYPE) ctype = TYPE_METHOD_BASETYPE (fntype); - /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a - class is in the (lexical) scope of the class in which it is - defined. */ + /* ISO C++ 11.4/5. A friend function defined in a class is in + the (lexical) scope of the class in which it is defined. */ if (!ctype && DECL_FRIEND_P (decl1)) { - ctype = DECL_CLASS_CONTEXT (decl1); + ctype = DECL_FRIEND_CONTEXT (decl1); /* CTYPE could be null here if we're dealing with a template; for example, `inline friend float foo()' inside a template @@ -13417,11 +13496,10 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) } last_function_parms = DECL_ARGUMENTS (decl1); - last_function_parm_tags = NULL_TREE; } else { - decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL_TREE); + decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL); /* 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; @@ -13431,8 +13509,8 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) restype = TREE_TYPE (fntype); if (CLASS_TYPE_P (restype) && !CLASSTYPE_GOT_SEMICOLON (restype)) { - cp_error ("semicolon missing after declaration of `%#T'", restype); - shadow_tag (build_expr_list (NULL_TREE, restype)); + error ("semicolon missing after declaration of `%#T'", restype); + shadow_tag (build_tree_list (NULL_TREE, restype)); CLASSTYPE_GOT_SEMICOLON (restype) = 1; if (TREE_CODE (fntype) == FUNCTION_TYPE) fntype = build_function_type (integer_type_node, @@ -13458,14 +13536,33 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) } } + if (DECL_DECLARED_INLINE_P (decl1) + && lookup_attribute ("noinline", attrs)) + warning_with_decl (decl1, + "inline function `%s' given attribute noinline"); + + if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1)) + /* This is a constructor, we must ensure that any default args + introduced by this definition are propagated to the clones + now. The clones are used directly in overload resolution. */ + adjust_clone_args (decl1); + + /* Sometimes we don't notice that a function is a static member, and + build a METHOD_TYPE for it. Fix that up now. */ + if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1) + && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE) + { + revert_static_member_fn (decl1); + last_function_parms = TREE_CHAIN (last_function_parms); + ctype = NULL_TREE; + } + /* Warn if function was previously implicitly declared (but not if we warned then). */ if (! warn_implicit && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE) cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))); - announce_function (decl1); - /* Set up current_class_type, and enter the scope of the class, if appropriate. */ if (ctype) @@ -13479,67 +13576,20 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) case where a template parameter has the same name as a field of the class.) It is not until after this point that PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly. */ - if (pre_parsed_p == 2) + if (flags & SF_INCLASS_INLINE) maybe_begin_member_template_processing (decl1); - /* We are now in the scope of the function being defined. */ - current_function_decl = decl1; - - /* 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; - - if (! processing_template_decl) - { - /* In a function definition, arg types must be complete. */ - require_complete_types_for_parms (current_function_parms); - - if (TYPE_SIZE (complete_type (TREE_TYPE (fntype))) == NULL_TREE) - { - cp_error ("return-type `%#T' is an incomplete type", - TREE_TYPE (fntype)); - - /* Make it return void instead, but don't change the - type of the DECL_RESULT, in case we have a named return value. */ - if (ctype) - TREE_TYPE (decl1) - = build_cplus_method_type (build_type_variant (ctype, - TREE_READONLY (decl1), - TREE_SIDE_EFFECTS (decl1)), - void_type_node, - FUNCTION_ARG_CHAIN (decl1)); - else - TREE_TYPE (decl1) - = build_function_type (void_type_node, - TYPE_ARG_TYPES (TREE_TYPE (decl1))); - DECL_RESULT (decl1) - = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype))); - TREE_READONLY (DECL_RESULT (decl1)) - = CP_TYPE_CONST_P (TREE_TYPE (fntype)); - TREE_THIS_VOLATILE (DECL_RESULT (decl1)) - = CP_TYPE_VOLATILE_P (TREE_TYPE (fntype)); - } - - if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype)) - && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype))) - abstract_virtuals_error (decl1, TREE_TYPE (fntype)); - } - - /* Effective C++ rule 15. See also c_expand_return. */ + /* Effective C++ rule 15. */ if (warn_ecpp - && DECL_NAME (decl1) == ansi_opname[(int) MODIFY_EXPR] + && DECL_OVERLOADED_OPERATOR_P (decl1) == NOP_EXPR && TREE_CODE (TREE_TYPE (fntype)) == VOID_TYPE) - cp_warning ("`operator=' should return a reference to `*this'"); + warning ("`operator=' should return a reference to `*this'"); /* Make the init_value nonzero so pushdecl knows this is not tentative. error_mark_node is replaced below (in poplevel) with the BLOCK. */ - DECL_INITIAL (decl1) = error_mark_node; + if (!DECL_INITIAL (decl1)) + DECL_INITIAL (decl1) = error_mark_node; -#ifdef SET_DEFAULT_DECL_ATTRIBUTES - SET_DEFAULT_DECL_ATTRIBUTES (decl1, attrs); -#endif - /* This function exists in static storage. (This does not mean `static' in the C sense!) */ TREE_STATIC (decl1) = 1; @@ -13551,14 +13601,64 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) if (processing_template_decl) decl1 = push_template_decl (decl1); + /* We are now in the scope of the function being defined. */ + current_function_decl = decl1; + + /* Save the parm names or decls from this function's declarator + where store_parm_decls will find them. */ + current_function_parms = last_function_parms; + + /* Make sure the parameter and return types are reasonable. When + you declare a function, these types can be incomplete, but they + must be complete when you define the function. */ + if (! processing_template_decl) + check_function_type (decl1, current_function_parms); + + /* Build the return declaration for the function. */ + restype = TREE_TYPE (fntype); + if (!processing_template_decl) + { + if (!DECL_RESULT (decl1)) + { + DECL_RESULT (decl1) + = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype)); + c_apply_type_quals_to_decl (cp_type_quals (restype), + DECL_RESULT (decl1)); + } + } + else + /* Just use `void'. Nobody will ever look at this anyhow. */ + DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, void_type_node); + + /* Initialize RTL machinery. We cannot do this until + CURRENT_FUNCTION_DECL and DECL_RESULT are set up. We do this + even when processing a template; this is how we get + CFUN set up, and our per-function variables initialized. + FIXME factor out the non-RTL stuff. */ + bl = current_binding_level; + init_function_start (decl1, input_filename, lineno); + current_binding_level = bl; + + /* Even though we're inside a function body, we still don't want to + call expand_expr to calculate the size of a variable-sized array. + We haven't necessarily assigned RTL to all variables yet, so it's + not safe to try to expand expressions involving them. */ + immediate_size_expand = 0; + cfun->x_dont_save_pending_sizes_p = 1; + + /* Start the statement-tree, start the tree now. */ + begin_stmt_tree (&DECL_SAVED_TREE (decl1)); + + /* Let the user know we're compiling this function. */ + announce_function (decl1); + /* Record the decl so that the function name is defined. If we already have a decl for this name, and it is a FUNCTION_DECL, use the old decl. */ - if (!processing_template_decl && pre_parsed_p == 0) + if (!processing_template_decl && !(flags & SF_PRE_PARSED)) { /* A specialization is not used to guide overload resolution. */ - if ((flag_guiding_decls - || !DECL_TEMPLATE_SPECIALIZATION (decl1)) + if (!DECL_TEMPLATE_SPECIALIZATION (decl1) && ! DECL_FUNCTION_MEMBER_P (decl1)) decl1 = pushdecl (decl1); else @@ -13569,20 +13669,63 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) /* And make sure we have enough default args. */ check_default_args (decl1); } - DECL_MAIN_VARIANT (decl1) = decl1; fntype = TREE_TYPE (decl1); } + /* Reset these in case the call to pushdecl changed them. */ current_function_decl = decl1; + cfun->decl = decl1; + + /* If we are (erroneously) defining a function that we have already + defined before, wipe out what we knew before. */ + if (!DECL_PENDING_INLINE_P (decl1) + && DECL_SAVED_FUNCTION_DATA (decl1)) + { + free (DECL_SAVED_FUNCTION_DATA (decl1)); + DECL_SAVED_FUNCTION_DATA (decl1) = NULL; + } + + if (ctype && !doing_friend && !DECL_STATIC_FUNCTION_P (decl1)) + { + /* We know that this was set up by `grokclassfn'. We do not + wait until `store_parm_decls', since evil parse errors may + never get us to that point. Here we keep the consistency + between `current_class_type' and `current_class_ptr'. */ + tree t = DECL_ARGUMENTS (decl1); + + my_friendly_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL, + 162); + my_friendly_assert (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE, + 19990811); + + cp_function_chain->x_current_class_ref + = build_indirect_ref (t, NULL); + cp_function_chain->x_current_class_ptr = t; + + /* Constructors and destructors need to know whether they're "in + charge" of initializing virtual base classes. */ + t = TREE_CHAIN (t); + if (DECL_HAS_IN_CHARGE_PARM_P (decl1)) + { + current_in_charge_parm = t; + t = TREE_CHAIN (t); + } + if (DECL_HAS_VTT_PARM_P (decl1)) + { + if (DECL_NAME (t) != vtt_parm_identifier) + abort (); + current_vtt_parm = t; + } + } if (DECL_INTERFACE_KNOWN (decl1)) { - tree ctx = hack_decl_function_context (decl1); + tree ctx = decl_function_context (decl1); if (DECL_NOT_REALLY_EXTERN (decl1)) DECL_EXTERNAL (decl1) = 0; - if (ctx != NULL_TREE && DECL_THIS_INLINE (ctx) + if (ctx != NULL_TREE && DECL_DECLARED_INLINE_P (ctx) && TREE_PUBLIC (ctx)) /* This is a function in a local class in an extern inline function. */ @@ -13595,12 +13738,14 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) && (! DECL_TEMPLATE_INSTANTIATION (decl1) || flag_alt_external_templates)) { - if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1) + if (DECL_DECLARED_INLINE_P (decl1) + || DECL_TEMPLATE_INSTANTIATION (decl1) || processing_template_decl) { DECL_EXTERNAL (decl1) = (interface_only - || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines + || (DECL_DECLARED_INLINE_P (decl1) + && ! flag_implement_inlines && !DECL_VINDEX (decl1))); /* For WIN32 we also want to put these in linkonce sections. */ @@ -13631,92 +13776,25 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) So clear DECL_EXTERNAL. */ DECL_EXTERNAL (decl1) = 0; - if ((DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)) + if ((DECL_DECLARED_INLINE_P (decl1) + || DECL_TEMPLATE_INSTANTIATION (decl1)) && ! DECL_INTERFACE_KNOWN (decl1) /* Don't try to defer nested functions for now. */ - && ! hack_decl_function_context (decl1)) + && ! decl_function_context (decl1)) DECL_DEFER_OUTPUT (decl1) = 1; else DECL_INTERFACE_KNOWN (decl1) = 1; } - if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) - { - if (TREE_CODE (fntype) == METHOD_TYPE) - TREE_TYPE (decl1) = fntype - = build_function_type (TREE_TYPE (fntype), - TREE_CHAIN (TYPE_ARG_TYPES (fntype))); - current_function_parms = TREE_CHAIN (current_function_parms); - DECL_ARGUMENTS (decl1) = current_function_parms; - ctype = NULL_TREE; - } - restype = TREE_TYPE (fntype); - - if (ctype) - { - /* If we're compiling a friend function, neither of the variables - current_class_ptr nor current_class_type will have values. */ - if (! doing_friend) - { - /* We know that this was set up by `grokclassfn'. - We do not wait until `store_parm_decls', since evil - parse errors may never get us to that point. Here - we keep the consistency between `current_class_type' - and `current_class_ptr'. */ - tree t = current_function_parms; - - my_friendly_assert (t != NULL_TREE - && TREE_CODE (t) == PARM_DECL, 162); - - if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE) - { - int i; - - if (! hack_decl_function_context (decl1)) - temporary_allocation (); - i = suspend_momentary (); - - /* Normally, build_indirect_ref returns - current_class_ref whenever current_class_ptr is - dereferenced. This time, however, we want it to - *create* current_class_ref, so we temporarily clear - current_class_ptr to fool it. */ - current_class_ptr = NULL_TREE; - current_class_ref = build_indirect_ref (t, NULL_PTR); - current_class_ptr = t; - - resume_momentary (i); - if (! hack_decl_function_context (decl1)) - end_temporary_allocation (); - } - else - /* We're having a signature pointer here. */ - current_class_ref = current_class_ptr = t; - - } - } - else - current_class_ptr = current_class_ref = NULL_TREE; - pushlevel (0); current_binding_level->parm_flag = 1; - GNU_xref_function (decl1, current_function_parms); - - if (attrs) - cplus_decl_attributes (decl1, NULL_TREE, attrs); - - make_function_rtl (decl1); + cplus_decl_attributes (&decl1, attrs, 0); /* Promote the value to int before returning it. */ - if (C_PROMOTING_INTEGER_TYPE_P (restype)) + if (c_promoting_integer_type_p (restype)) restype = type_promotes_to (restype); - /* If this fcn was already referenced via a block-scope `extern' decl - (or an implicit decl), propagate certain information about the usage. */ - if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) - TREE_ADDRESSABLE (decl1) = 1; - if (DECL_RESULT (decl1) == NULL_TREE) { DECL_RESULT (decl1) @@ -13725,138 +13803,68 @@ start_function (declspecs, declarator, attrs, pre_parsed_p) TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = CP_TYPE_VOLATILE_P (restype); } - /* Allocate further tree nodes temporarily during compilation - of this function only. Tiemann moved up here from bottom of fn. */ - /* If this is a nested function, then we must continue to allocate RTL - on the permanent obstack in case we need to inline it later. */ - if (! hack_decl_function_context (decl1)) - temporary_allocation (); - - if (processing_template_decl) - { - ++minimal_parse_mode; - last_tree = DECL_SAVED_TREE (decl1) - = build_nt (EXPR_STMT, void_zero_node); - } - ++function_depth; - if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)) - && DECL_LANGUAGE (decl1) == lang_cplusplus) + if (DECL_DESTRUCTOR_P (decl1)) { dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); - ctor_label = NULL_TREE; - } - else - { - dtor_label = NULL_TREE; - if (DECL_CONSTRUCTOR_P (decl1)) - ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + DECL_CONTEXT (dtor_label) = current_function_decl; } + start_fname_decls (); + + store_parm_decls (current_function_parms); + return 1; } -/* Called after store_parm_decls for a function-try-block. We need to update - last_parm_cleanup_insn so that the base initializers for a constructor - are run within this block, not before it. */ - -void -expand_start_early_try_stmts () -{ - expand_start_try_stmts (); - last_parm_cleanup_insn = get_last_insn (); -} - /* Store the parameter declarations into the current function declaration. This is called after parsing the parameter declarations, before digesting the body of the function. Also install to binding contour return value identifier, if any. */ -void -store_parm_decls () +static void +store_parm_decls (current_function_parms) + tree current_function_parms; { register tree fndecl = current_function_decl; register tree parm; - int parms_have_cleanups = 0; - tree cleanups = NULL_TREE; - - /* This is either a chain of PARM_DECLs (when a prototype is used). */ - tree specparms = current_function_parms; - - /* 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. */ tree nonparms = NULL_TREE; - if (toplevel_bindings_p ()) - fatal ("parse errors have confused me too much"); - - /* Initialize RTL machinery. */ - init_function_start (fndecl, input_filename, lineno); - - /* Create a binding level for the parms. */ - expand_start_bindings (0); - - if (specparms != NULL_TREE) + if (current_function_parms) { /* This case is when the function was defined with an ANSI prototype. The parms already have decls, so we need not do anything here except record them as in effect and complain if any redundant old-style parm decls were written. */ - register tree next; + tree specparms = current_function_parms; + tree next; /* Must clear this because it might contain TYPE_DECLs declared - at class level. */ + at class level. */ storedecls (NULL_TREE); - for (parm = nreverse (specparms); parm; parm = next) + /* If we're doing semantic analysis, then we'll call pushdecl + for each of these. We must do them in reverse order so that + they end in the correct forward order. */ + specparms = nreverse (specparms); + + for (parm = specparms; parm; parm = next) { next = TREE_CHAIN (parm); if (TREE_CODE (parm) == PARM_DECL) { - tree cleanup; - if (DECL_NAME (parm) == NULL_TREE) - { - pushdecl (parm); - } - else if (TREE_CODE (TREE_TYPE (parm)) == VOID_TYPE) - cp_error ("parameter `%D' declared void", parm); + if (DECL_NAME (parm) == NULL_TREE + || TREE_CODE (parm) != VOID_TYPE) + pushdecl (parm); else - { - /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls. - A parameter is assumed not to have any side effects. - If this should change for any reason, then this - will have to wrap the bashed reference type in a save_expr. - - Also, if the parameter type is declared to be an X - and there is an X(X&) constructor, we cannot lay it - into the stack (any more), so we make this parameter - look like it is really of reference type. Functions - which pass parameters to this function will know to - create a temporary in their frame, and pass a reference - to that. */ - - if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE - && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm)))) - SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm)); - - pushdecl (parm); - } - if (! processing_template_decl - && (cleanup = maybe_build_cleanup (parm), cleanup)) - { - expand_decl (parm); - parms_have_cleanups = 1; - - /* Keep track of the cleanups. */ - cleanups = tree_cons (parm, cleanup, cleanups); - } + error ("parameter `%D' declared void", parm); } else { @@ -13867,12 +13875,11 @@ store_parm_decls () } } - /* Get the decls in their original chain order - and record in the function. This is all and only the - PARM_DECLs that were pushed into scope by the loop above. */ + /* Get the decls in their original chain order and record in the + 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; @@ -13881,779 +13888,395 @@ store_parm_decls () as the decl-chain of the current lexical scope. Put the enumerators in as well, at the front so that DECL_ARGUMENTS is not modified. */ - storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); - /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ - declare_function_name (); - - /* Initialize the RTL code for the function. */ - DECL_SAVED_INSNS (fndecl) = NULL_RTX; - if (! processing_template_decl) - expand_function_start (fndecl, parms_have_cleanups); - - current_function_parms_stored = 1; - - /* If this function is `main', emit a call to `__main' - to run global initializers, etc. */ - if (DECL_MAIN_P (fndecl)) - expand_main_function (); - - /* Now that we have initialized the parms, we can start their - cleanups. We cannot do this before, since expand_decl_cleanup - should not be called before the parm can be used. */ - if (cleanups - && ! processing_template_decl) - { - for (cleanups = nreverse (cleanups); cleanups; cleanups = TREE_CHAIN (cleanups)) - { - if (! expand_decl_cleanup (TREE_PURPOSE (cleanups), TREE_VALUE (cleanups))) - cp_error ("parser lost in parsing declaration of `%D'", - TREE_PURPOSE (cleanups)); - } - } - - /* Create a binding contour which can be used to catch - cleanup-generated temporaries. Also, if the return value needs or - has initialization, deal with that now. */ - if (parms_have_cleanups) - { - pushlevel (0); - expand_start_bindings (0); - } - - if (! processing_template_decl && flag_exceptions) - { - /* Do the starting of the exception specifications, if we have any. */ - if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) - expand_start_eh_spec (); - } - - last_parm_cleanup_insn = get_last_insn (); - last_dtor_insn = get_last_insn (); -} - -/* Bind a name and initialization to the return value of - the current function. */ - -void -store_return_init (return_id, init) - tree return_id, init; -{ - tree decl = DECL_RESULT (current_function_decl); - - if (pedantic) - /* Give this error as many times as there are occurrences, - so that users can use Emacs compilation buffers to find - and fix all such places. */ - pedwarn ("ANSI C++ does not permit named return values"); - - if (return_id != NULL_TREE) - { - if (DECL_NAME (decl) == NULL_TREE) - { - DECL_NAME (decl) = return_id; - DECL_ASSEMBLER_NAME (decl) = return_id; - } - else - cp_error ("return identifier `%D' already in place", decl); - } - - /* Can't let this happen for constructors. */ - if (DECL_CONSTRUCTOR_P (current_function_decl)) - { - error ("can't redefine default return value for constructors"); - return; - } - - /* If we have a named return value, put that in our scope as well. */ - if (DECL_NAME (decl) != NULL_TREE) - { - /* If this named return value comes in a register, - put it in a pseudo-register. */ - if (DECL_REGISTER (decl)) - { - original_result_rtx = DECL_RTL (decl); - DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); - } - - /* Let `cp_finish_decl' know that this initializer is ok. */ - DECL_INITIAL (decl) = init; - pushdecl (decl); - - if (minimal_parse_mode) - add_tree (build_min_nt (RETURN_INIT, return_id, - copy_to_permanent (init))); - else - cp_finish_decl (decl, init, NULL_TREE, 0, 0); - } + /* Do the starting of the exception specifications, if we have any. */ + if (flag_exceptions && !processing_template_decl + && flag_enforce_eh_specs + && TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) + current_eh_spec_block = begin_eh_spec_block (); } -/* Emit implicit code for a destructor. This is a subroutine of - finish_function. */ +/* We have finished doing semantic analysis on DECL, but have not yet + generated RTL for its body. Save away our current state, so that + when we want to generate RTL later we know what to do. */ static void -finish_dtor () +save_function_data (decl) + tree decl; { - tree binfo = TYPE_BINFO (current_class_type); - tree cond = integer_one_node; - tree exprstmt; - tree in_charge_node = lookup_name (in_charge_identifier, 0); - tree virtual_size; - int ok_to_optimize_dtor = 0; - int empty_dtor = get_last_insn () == last_dtor_insn; - rtx insns, last_parm_insn; - - if (current_function_assigns_this) - cond = build (NE_EXPR, boolean_type_node, - current_class_ptr, integer_zero_node); - else - { - int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); + struct cp_language_function *f; - /* If this destructor is empty, then we don't need to check - whether `this' is NULL in some cases. */ - if ((flag_this_is_variable & 1) == 0) - ok_to_optimize_dtor = 1; - else if (empty_dtor) - ok_to_optimize_dtor - = (n_baseclasses == 0 - || (n_baseclasses == 1 - && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); - } + /* Save the language-specific per-function data so that we can + get it back when we really expand this function. */ + my_friendly_assert (!DECL_PENDING_INLINE_P (decl), + 19990908); - /* If this has a vlist1 parameter, allocate the corresponding vlist - parameter. */ - if (DECL_DESTRUCTOR_FOR_PVBASE_P (current_function_decl)) - { - /* _Vlist __vlist; */ - tree vlist; + /* Make a copy. */ + f = ((struct cp_language_function *) + xmalloc (sizeof (struct cp_language_function))); + memcpy (f, cp_function_chain, sizeof (struct cp_language_function)); + DECL_SAVED_FUNCTION_DATA (decl) = f; - mark_all_temps_used(); - vlist = pushdecl (build_decl (VAR_DECL, vlist_identifier, - vlist_type_node)); - TREE_USED (vlist) = 1; - DECL_ARTIFICIAL (vlist) = 1; - expand_decl (vlist); - expand_decl_init (vlist); - } + /* Clear out the bits we don't need. */ + f->base.x_stmt_tree.x_last_stmt = NULL_TREE; + f->base.x_stmt_tree.x_last_expr_type = NULL_TREE; + f->x_named_label_uses = NULL; + f->bindings = NULL; + f->x_local_names = NULL; - /* These initializations might go inline. Protect - the binding level of the parms. */ - pushlevel (0); - expand_start_bindings (0); + /* When we get back here again, we will be expanding. */ + f->x_expanding_p = 1; - if (current_function_assigns_this) + /* If we've already decided that we cannot inline this function, we + must remember that fact when we actually go to expand the + function. */ + if (current_function_cannot_inline) { - current_function_assigns_this = 0; - current_function_just_assigned_this = 0; + f->cannot_inline = current_function_cannot_inline; + DECL_INLINE (decl) = 0; } +} - /* Generate the code to call destructor on base class. - If this destructor belongs to a class with virtual - functions, then set the virtual function table - pointer to represent the type of our base class. */ - - /* This side-effect makes call to `build_delete' generate the - code we have to have at the end of this destructor. - `build_delete' will set the flag again. */ - TYPE_HAS_DESTRUCTOR (current_class_type) = 0; - - /* These are two cases where we cannot delegate deletion. */ - if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) - || TYPE_GETS_REG_DELETE (current_class_type)) - exprstmt = build_delete - (current_class_type, current_class_ref, integer_zero_node, - LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); - else - exprstmt = build_delete - (current_class_type, current_class_ref, in_charge_node, - LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); - - /* If we did not assign to this, then `this' is non-zero at - the end of a destructor. As a special optimization, don't - emit test if this is an empty destructor. If it does nothing, - it does nothing. If it calls a base destructor, the base - destructor will perform the test. */ - - if (exprstmt != error_mark_node - && (TREE_CODE (exprstmt) != NOP_EXPR - || TREE_OPERAND (exprstmt, 0) != integer_zero_node - || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) - { - expand_label (dtor_label); - if (cond != integer_one_node) - expand_start_cond (cond, 0); - if (exprstmt != void_zero_node) - /* Don't call `expand_expr_stmt' if we're not going to do - anything, since -Wall will give a diagnostic. */ - expand_expr_stmt (exprstmt); - - /* Run destructor on all virtual baseclasses. */ - if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) - { - tree vbases = nreverse - (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); - expand_start_cond (build (BIT_AND_EXPR, integer_type_node, - in_charge_node, integer_two_node), 0); - while (vbases) - { - if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) - { - tree vb = get_vbase - (BINFO_TYPE (vbases), - TYPE_BINFO (current_class_type)); +/* Add a note to mark the beginning of the main body of the constructor. + This is used to set up the data structures for the cleanup regions for + fully-constructed bases and members. */ - expand_expr_stmt - (build_base_dtor_call (current_class_ref, - vb, integer_zero_node)); - } - vbases = TREE_CHAIN (vbases); - } - expand_end_cond (); - } +static void +begin_constructor_body () +{ + tree ctor_stmt = build_stmt (CTOR_STMT); + CTOR_BEGIN_P (ctor_stmt) = 1; + add_stmt (ctor_stmt); +} - do_pending_stack_adjust (); - if (cond != integer_one_node) - expand_end_cond (); - } +/* Add a note to mark the end of the main body of the constructor. This is + used to end the cleanup regions for fully-constructed bases and + members. */ - virtual_size = c_sizeof (current_class_type); +static void +finish_constructor_body () +{ + /* Mark the end of the cleanups for a partially constructed object. - /* At the end, call delete if that's what's requested. */ + ??? These should really be handled automatically by closing the block, + as with the destructor cleanups; the only difference is that these are + only run if an exception is thrown. */ + add_stmt (build_stmt (CTOR_STMT)); +} - /* FDIS sez: At the point of definition of a virtual destructor - (including an implicit definition), non-placement operator - delete shall be looked up in the scope of the destructor's - class and if found shall be accessible and unambiguous. +/* Do all the processing for the beginning of a destructor; set up the + vtable pointers and cleanups for bases and members. */ - This is somewhat unclear, but I take it to mean that if the - class only defines placement deletes we don't do anything here. - So we pass LOOKUP_SPECULATIVELY; delete_sanity will complain - for us if they ever try to delete one of these. */ +static void +begin_destructor_body () +{ + tree if_stmt; + tree compound_stmt; - if (TYPE_GETS_REG_DELETE (current_class_type) - || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) - exprstmt = build_op_delete_call - (DELETE_EXPR, current_class_ptr, virtual_size, - LOOKUP_NORMAL | LOOKUP_SPECULATIVELY, NULL_TREE); - else - exprstmt = NULL_TREE; - - if (exprstmt) - { - cond = build (BIT_AND_EXPR, integer_type_node, - in_charge_node, integer_one_node); - expand_start_cond (cond, 0); - expand_expr_stmt (exprstmt); - expand_end_cond (); - } - - /* End of destructor. */ - expand_end_bindings (NULL_TREE, getdecls () != NULL_TREE, 0); - poplevel (getdecls () != NULL_TREE, 0, 0); - - /* Back to the top of destructor. */ - /* Don't execute destructor code if `this' is NULL. */ - - start_sequence (); - - /* If we need thunk-style vlists, initialize them if the caller did - not pass them. This requires a new temporary. The generated code - looks like - if (!(__in_charge & 4)) - __vlist = __vl.<type> + sizeof(__vl.<type>); - else - __vlist = __vlist1; - */ - if (TYPE_USES_PVBASES (current_class_type)) - { - tree vlist = lookup_name (vlist_identifier, 0); - tree vlist1 = lookup_name (get_identifier (VLIST1_NAME), 0); - cond = build (BIT_AND_EXPR, integer_type_node, - in_charge_node, build_int_2 (4, 0)); - cond = build1 (TRUTH_NOT_EXPR, boolean_type_node, cond); - expand_start_cond (cond, 0); - init_vlist (current_class_type); - expand_start_else (); - expand_expr_stmt (build_modify_expr (vlist, NOP_EXPR, vlist1)); - expand_end_cond (); - } - - /* If the dtor is empty, and we know there is not possible way we - could use any vtable entries, before they are possibly set by - a base class dtor, we don't have to setup the vtables, as we - know that any base class dtoring will set up any vtables it - needs. We avoid MI, because one base class dtor can do a + /* If the dtor is empty, and we know there is not any possible + way we could use any vtable entries, before they are possibly + set by a base class dtor, we don't have to setup the vtables, + as we know that any base class dtor will set up any vtables + it needs. We avoid MI, because one base class dtor can do a virtual dispatch to an overridden function that would need to have a non-related vtable set up, we cannot avoid setting up - vtables in that case. We could change this to see if there is - just one vtable. */ - if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type)) - { - /* Make all virtual function table pointers in non-virtual base - classes point to CURRENT_CLASS_TYPE's virtual function - tables. */ - expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr); + vtables in that case. We could change this to see if there + is just one vtable. - if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) - expand_indirect_vtbls_init (binfo, current_class_ref, current_class_ptr); - } + ??? In the destructor for a class, the vtables are set + appropriately for that class. There will be no non-related + vtables. jason 2001-12-11. */ + if_stmt = begin_if_stmt (); - if (! ok_to_optimize_dtor) - { - cond = build_binary_op (NE_EXPR, - current_class_ptr, integer_zero_node); - expand_start_cond (cond, 0); - } + /* If it is not safe to avoid setting up the vtables, then + someone will change the condition to be boolean_true_node. + (Actually, for now, we do not have code to set the condition + appropriately, so we just assume that we always need to + initialize the vtables.) */ + finish_if_stmt_cond (boolean_true_node, if_stmt); + current_vcalls_possible_p = &IF_COND (if_stmt); - insns = get_insns (); - end_sequence (); + compound_stmt = begin_compound_stmt (/*has_no_scope=*/0); - last_parm_insn = get_first_nonparm_insn (); - if (last_parm_insn == NULL_RTX) - last_parm_insn = get_last_insn (); - else - last_parm_insn = previous_insn (last_parm_insn); + /* Make all virtual function table pointers in non-virtual base + classes point to CURRENT_CLASS_TYPE's virtual function + tables. */ + initialize_vtbl_ptrs (current_class_ptr); - emit_insns_after (insns, last_parm_insn); + finish_compound_stmt (/*has_no_scope=*/0, compound_stmt); + finish_then_clause (if_stmt); + finish_if_stmt (); - if (! ok_to_optimize_dtor) - expand_end_cond (); + /* And insert cleanups for our bases and members so that they + will be properly destroyed if we throw. */ + push_base_cleanups (); } -/* Emit implicit code for a constructor. This is a subroutine of - finish_function. CALL_POPLEVEL is the same variable in - finish_function. */ +/* At the end of every destructor we generate code to delete the object if + necessary. Do that now. */ static void -finish_ctor (call_poplevel) - int call_poplevel; +finish_destructor_body () { - register tree fndecl = current_function_decl; - tree cond = NULL_TREE, thenclause = NULL_TREE; - rtx insns; - tree decls; - - /* Allow constructor for a type to get a new instance of the object - using `build_new'. */ - tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); - CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; + tree exprstmt; - if (flag_this_is_variable > 0) + /* In a virtual destructor, we must call delete. */ + if (DECL_VIRTUAL_P (current_function_decl)) { - cond = build_binary_op (EQ_EXPR, current_class_ptr, integer_zero_node); - thenclause = - build_modify_expr (current_class_ptr, NOP_EXPR, - build_new (NULL_TREE, current_class_type, - void_type_node, 0)); - } + tree if_stmt; + tree virtual_size = c_sizeof (current_class_type); - CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; + /* [class.dtor] - start_sequence (); + At the point of definition of a virtual destructor (including + an implicit definition), non-placement operator delete shall + be looked up in the scope of the destructor's class and if + found shall be accessible and unambiguous. */ + exprstmt = build_op_delete_call + (DELETE_EXPR, current_class_ptr, virtual_size, + LOOKUP_NORMAL | LOOKUP_SPECULATIVELY, NULL_TREE); - if (flag_this_is_variable > 0) - { - expand_start_cond (cond, 0); - expand_expr_stmt (thenclause); - expand_end_cond (); + if_stmt = begin_if_stmt (); + finish_if_stmt_cond (build (BIT_AND_EXPR, integer_type_node, + current_in_charge_parm, + integer_one_node), + if_stmt); + finish_expr_stmt (exprstmt); + finish_then_clause (if_stmt); + finish_if_stmt (); } +} - /* Emit insns from `emit_base_init' which sets up virtual - function table pointer(s). */ - if (base_init_expr) - { - expand_expr_stmt (base_init_expr); - base_init_expr = NULL_TREE; - } +/* Do the necessary processing for the beginning of a function body, which + in this case includes member-initializers, but not the catch clauses of + a function-try-block. Currently, this means opening a binding level + for the member-initializers (in a ctor) and member cleanups (in a dtor). + In other functions, this isn't necessary, but it doesn't hurt. */ - insns = get_insns (); - end_sequence (); +tree +begin_function_body () +{ + tree stmt; - /* This is where the body of the constructor begins. */ + if (processing_template_decl) + /* Do nothing now. */; + else + /* Always keep the BLOCK node associated with the outermost pair of + curly braces of a function. These are needed for correct + operation of dwarfout.c. */ + keep_next_level (1); - emit_insns_after (insns, last_parm_cleanup_insn); + stmt = begin_compound_stmt (0); + COMPOUND_STMT_BODY_BLOCK (stmt) = 1; - end_protect_partials (); + if (processing_template_decl) + /* Do nothing now. */; + else if (DECL_CONSTRUCTOR_P (current_function_decl)) + begin_constructor_body (); + else if (DECL_DESTRUCTOR_P (current_function_decl)) + begin_destructor_body (); - /* This is where the body of the constructor ends. */ - expand_label (ctor_label); - ctor_label = NULL_TREE; + return stmt; +} - if (call_poplevel) - { - decls = getdecls (); - expand_end_bindings (decls, decls != NULL_TREE, 0); - poplevel (decls != NULL_TREE, 1, 0); - } +/* Do the processing for the end of a function body. Currently, this means + closing out the cleanups for fully-constructed bases and members, and in + the case of the destructor, deleting the object if desired. Again, this + is only meaningful for [cd]tors, since they are the only functions where + there is a significant distinction between the main body and any + function catch clauses. Handling, say, main() return semantics here + would be wrong, as flowing off the end of a function catch clause for + main() would also need to return 0. */ - /* c_expand_return knows to return 'this' from a constructor. */ - c_expand_return (NULL_TREE); +void +finish_function_body (compstmt) + tree compstmt; +{ + if (processing_template_decl) + /* Do nothing now. */; + else if (DECL_DESTRUCTOR_P (current_function_decl)) + /* Any return from a destructor will end up here. Put it before the + cleanups so that an explicit return doesn't duplicate them. */ + add_stmt (build_stmt (LABEL_STMT, dtor_label)); - current_function_assigns_this = 0; - current_function_just_assigned_this = 0; -} + /* Close the block; in a destructor, run the member cleanups. */ + finish_compound_stmt (0, compstmt); + if (processing_template_decl) + /* Do nothing now. */; + else if (DECL_CONSTRUCTOR_P (current_function_decl)) + finish_constructor_body (); + else if (DECL_DESTRUCTOR_P (current_function_decl)) + finish_destructor_body (); +} /* Finish up a function declaration and compile that function all the way to assembler language output. The free the storage for the function definition. - This is called after parsing the body of the function definition. - LINENO is the current line number. - - FLAGS is a bitwise or of the following values: - 1 - CALL_POPLEVEL - An extra call to poplevel (and expand_end_bindings) must be - made to take care of the binding contour for the base - initializers. This is only relevant for constructors. + FLAGS is a bitwise or of the following values: 2 - INCLASS_INLINE We just finished processing the body of an in-class inline function definition. (This processing will have taken place - after the class definition is complete.) + after the class definition is complete.) */ - NESTED is nonzero if we were in the middle of compiling another function - when we started on this one. */ - -void -finish_function (lineno, flags, nested) - int lineno; +tree +finish_function (flags) int flags; - int nested; { register tree fndecl = current_function_decl; tree fntype, ctype = NULL_TREE; - /* Label to use if this function is supposed to return a value. */ - tree no_return_label = NULL_TREE; - tree decls = NULL_TREE; - int call_poplevel = (flags & 1) != 0; int inclass_inline = (flags & 2) != 0; - int in_template; + int nested; /* When we get some parse errors, we can end up without a current_function_decl, so cope. */ if (fndecl == NULL_TREE) - return; - - if (function_depth > 1) - nested = 1; + return error_mark_node; + nested = function_depth > 1; fntype = TREE_TYPE (fndecl); -/* TREE_READONLY (fndecl) = 1; - This caused &foo to be of type ptr-to-const-function - which then got a warning when stored in a ptr-to-function variable. */ + /* TREE_READONLY (fndecl) = 1; + This caused &foo to be of type ptr-to-const-function + which then got a warning when stored in a ptr-to-function variable. */ - /* This happens on strange parse errors. */ - if (! current_function_parms_stored) - { - call_poplevel = 0; - store_parm_decls (); - } + my_friendly_assert (building_stmt_tree (), 20000911); - if (processing_template_decl) - { - if (DECL_CONSTRUCTOR_P (fndecl) && call_poplevel) - { - decls = getdecls (); - expand_end_bindings (decls, decls != NULL_TREE, 0); - poplevel (decls != NULL_TREE, 0, 0); - } - } - else + finish_fname_decls (); + + /* For a cloned function, we've already got all the code we need; + there's no need to add any extra bits. */ + if (!DECL_CLONED_FUNCTION_P (fndecl)) { - if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/) - { - tree ttype = target_type (fntype); - tree parmdecl; - - if (IS_AGGR_TYPE (ttype)) - /* Let debugger know it should output info for this type. */ - note_debug_info_needed (ttype); - - for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) - { - ttype = target_type (TREE_TYPE (parmdecl)); - if (IS_AGGR_TYPE (ttype)) - /* Let debugger know it should output info for this type. */ - note_debug_info_needed (ttype); - } - } - - /* Clean house because we will need to reorder insns here. */ - do_pending_stack_adjust (); - - if (dtor_label) - finish_dtor (); - else if (current_function_assigns_this) - { - /* Does not need to call emit_base_init, because - that is done (if needed) just after assignment to this - is seen. */ - - if (DECL_CONSTRUCTOR_P (current_function_decl)) - { - end_protect_partials (); - expand_label (ctor_label); - ctor_label = NULL_TREE; - - if (call_poplevel) - { - decls = getdecls (); - expand_end_bindings (decls, decls != NULL_TREE, 0); - poplevel (decls != NULL_TREE, 0, 0); - } - /* c_expand_return knows to return 'this' from a constructor. */ - c_expand_return (NULL_TREE); - } - else if (TREE_CODE (TREE_TYPE (DECL_RESULT (current_function_decl))) != VOID_TYPE - && return_label != NULL_RTX) - no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); - - current_function_assigns_this = 0; - current_function_just_assigned_this = 0; - base_init_expr = NULL_TREE; - } - else if (DECL_CONSTRUCTOR_P (fndecl) - && !DECL_VLIST_CTOR_WRAPPER_P (fndecl)) - finish_ctor (call_poplevel); - else if (DECL_MAIN_P (fndecl)) + if (DECL_MAIN_P (current_function_decl)) { /* Make it so that `main' always returns 0 by default. */ -#ifdef VMS - c_expand_return (integer_one_node); +#ifdef VMS_TARGET + finish_return_stmt (integer_one_node); #else - c_expand_return (integer_zero_node); + finish_return_stmt (integer_zero_node); #endif } - else if (return_label != NULL_RTX - && current_function_return_value == NULL_TREE - && ! DECL_NAME (DECL_RESULT (current_function_decl))) - no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); - - if (flag_exceptions) - expand_exception_blocks (); - - /* If this function is supposed to return a value, ensure that - we do not fall into the cleanups by mistake. The end of our - function will look like this: - - user code (may have return stmt somewhere) - goto no_return_label - cleanup_label: - cleanups - goto return_label - no_return_label: - NOTE_INSN_FUNCTION_END - return_label: - things for return - - If the user omits a return stmt in the USER CODE section, we - will have a control path which reaches NOTE_INSN_FUNCTION_END. - Otherwise, we won't. */ - if (no_return_label) - { - DECL_CONTEXT (no_return_label) = fndecl; - DECL_INITIAL (no_return_label) = error_mark_node; - DECL_SOURCE_FILE (no_return_label) = input_filename; - DECL_SOURCE_LINE (no_return_label) = lineno; - expand_goto (no_return_label); - } - - if (cleanup_label) - { - /* Remove the binding contour which is used - to catch cleanup-generated temporaries. */ - expand_end_bindings (0, 0, 0); - poplevel (0, 0, 0); - - /* Emit label at beginning of cleanup code for parameters. */ - emit_label (cleanup_label); - } - - /* Get return value into register if that's where it's supposed to be. */ - if (original_result_rtx) - fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); - - /* Finish building code that will trigger warnings if users forget - to make their functions return values. */ - if (no_return_label || cleanup_label) - emit_jump (return_label); - if (no_return_label) - { - /* We don't need to call `expand_*_return' here because we - don't need any cleanups here--this path of code is only - for error checking purposes. */ - expand_label (no_return_label); - } - - /* Generate rtl for function exit. */ - expand_function_end (input_filename, lineno, 1); - } - - /* If we're processing a template, squirrel away the definition - until we do an instantiation. */ - if (processing_template_decl) - { - --minimal_parse_mode; - DECL_SAVED_TREE (fndecl) = TREE_CHAIN (DECL_SAVED_TREE (fndecl)); - /* We have to save this value here in case - maybe_end_member_template_processing decides to pop all the - template parameters. */ - in_template = 1; + + /* Finish dealing with exception specifiers. */ + if (flag_exceptions && !processing_template_decl + && flag_enforce_eh_specs + && TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) + finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS + (TREE_TYPE (current_function_decl)), + current_eh_spec_block); } - else - in_template = 0; + + /* If we're saving up tree structure, tie off the function now. */ + finish_stmt_tree (&DECL_SAVED_TREE (fndecl)); /* This must come after expand_function_end because cleanups might have declarations (from inline functions) that need to go into this function's blocks. */ + + /* If the current binding level isn't the outermost binding level + for this function, either there is a bug, or we have experienced + syntax errors and the statement tree is malformed. */ if (current_binding_level->parm_flag != 1) - my_friendly_abort (122); - poplevel (1, 0, 1); - - /* If this is a in-class inline definition, we may have to pop the - bindings for the template parameters that we added in - maybe_begin_member_template_processing when start_function was - called. */ - if (inclass_inline) - maybe_end_member_template_processing (); - - /* Reset scope for C++: if we were in the scope of a class, - then when we finish this function, we are not longer so. - This cannot be done until we know for sure that no more - class members will ever be referenced in this function - (i.e., calls to destructors). */ - if (current_class_name) { - ctype = current_class_type; - pop_nested_class (); - } + /* Make sure we have already experienced errors. */ + if (errorcount == 0) + abort (); - /* Must mark the RESULT_DECL as being in this function. */ - DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; + /* Throw away the broken statement tree and extra binding + levels. */ + DECL_SAVED_TREE (fndecl) = build_stmt (COMPOUND_STMT, NULL_TREE); - /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point - to the FUNCTION_DECL node itself. */ - BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; + while (current_binding_level->parm_flag != 1) + { + if (current_binding_level->parm_flag == 2) + pop_nested_class (); + else + poplevel (0, 0, 0); + } + } + poplevel (1, 0, 1); - if (!in_template) + /* Set up the named return value optimization, if we can. Here, we + eliminate the copy from the nrv into the RESULT_DECL and any cleanup + for the nrv. genrtl_start_function and declare_return_variable + handle making the nrv and RESULT_DECL share space. */ + if (current_function_return_value) { - int saved_flag_keep_inline_functions = - flag_keep_inline_functions; - - /* So we can tell if jump_optimize sets it to 1. */ - can_reach_end = 0; - - if (DECL_CONTEXT (fndecl) != NULL_TREE - && hack_decl_function_context (fndecl)) - /* Trick rest_of_compilation into not deferring output of this - function, even if it is inline, since the rtl_obstack for - this function is the function_obstack of the enclosing - function and will be deallocated when the enclosing - function is gone. See save_tree_status. */ - flag_keep_inline_functions = 1; - - /* Run the optimizers and output the assembler code for this - function. */ - - if (DECL_ARTIFICIAL (fndecl)) + tree r = current_function_return_value; + /* This is only worth doing for fns that return in memory--and + simpler, since we don't have to worry about promoted modes. */ + if (r != error_mark_node + && aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl)))) { - /* Do we really *want* to inline this synthesized method? */ - - int save_fif = flag_inline_functions; - flag_inline_functions = 1; - - /* Turn off DECL_INLINE for the moment so function_cannot_inline_p - will check our size. */ - DECL_INLINE (fndecl) = 0; - - rest_of_compilation (fndecl); - flag_inline_functions = save_fif; + DECL_ALIGN (r) = DECL_ALIGN (DECL_RESULT (fndecl)); + walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl), + nullify_returns_r, r); } else - rest_of_compilation (fndecl); + /* Clear it so genrtl_start_function and declare_return_variable + know we're not optimizing. */ + current_function_return_value = NULL_TREE; + } - flag_keep_inline_functions = saved_flag_keep_inline_functions; + /* Remember that we were in class scope. */ + if (current_class_name) + ctype = current_class_type; - if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl)) - { - /* Set DECL_EXTERNAL so that assemble_external will be called as - necessary. We'll clear it again in finish_file. */ - if (! DECL_EXTERNAL (fndecl)) - DECL_NOT_REALLY_EXTERN (fndecl) = 1; - DECL_EXTERNAL (fndecl) = 1; - mark_inline_for_output (fndecl); - } + /* Must mark the RESULT_DECL as being in this function. */ + DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; - if (ctype && TREE_ASM_WRITTEN (fndecl)) - note_debug_info_needed (ctype); + /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point + to the FUNCTION_DECL node itself. */ + BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; - current_function_returns_null |= can_reach_end; + /* Save away current state, if appropriate. */ + if (!processing_template_decl) + save_function_data (fndecl); + + /* If this function calls `setjmp' it cannot be inlined. When + `longjmp' is called it is not guaranteed to restore the value of + local variables that have been modified since the call to + `setjmp'. So, if were to inline this function into some caller + `c', then when we `longjmp', we might not restore all variables + in `c'. (It might seem, at first blush, that there's no way for + this function to modify local variables in `c', but their + addresses may have been stored somewhere accessible to this + function.) */ + if (!processing_template_decl && calls_setjmp_p (fndecl)) + DECL_UNINLINABLE (fndecl) = 1; + + /* Clear out memory we no longer need. */ + free_after_parsing (cfun); + /* Since we never call rest_of_compilation, we never clear + CFUN. Do so explicitly. */ + free_after_compilation (cfun); + cfun = NULL; - /* Since we don't normally go through c_expand_return for constructors, - this normally gets the wrong value. - Also, named return values have their return codes emitted after - NOTE_INSN_FUNCTION_END, confusing jump.c. */ - if (DECL_CONSTRUCTOR_P (fndecl) - || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) - current_function_returns_null = 0; + /* If this is a in-class inline definition, we may have to pop the + bindings for the template parameters that we added in + maybe_begin_member_template_processing when start_function was + called. */ + if (inclass_inline) + maybe_end_member_template_processing (); - if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) - cp_warning ("`noreturn' function `%D' does return", fndecl); - else if ((warn_return_type || pedantic) - && current_function_returns_null - && TREE_CODE (TREE_TYPE (fntype)) != VOID_TYPE) - { - /* If this function returns non-void and control can drop through, - complain. */ - cp_warning ("control reaches end of non-void function `%D'", fndecl); - } - /* With just -W, complain only if function returns both with - and without a value. */ - else if (extra_warnings - && current_function_returns_value && current_function_returns_null) - warning ("this function may return with or without a value"); - } + /* Leave the scope of the class. */ + if (ctype) + pop_nested_class (); --function_depth; - /* Free all the tree nodes making up this function. */ - /* Switch back to allocating nodes permanently - until we start another function. */ - if (! nested) - permanent_allocation (1); - - if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) - { - tree t; - - /* Stop pointing to the local nodes about to be freed. */ - /* But DECL_INITIAL must remain nonzero so we know this - was an actual function definition. */ - DECL_INITIAL (fndecl) = error_mark_node; - for (t = DECL_ARGUMENTS (fndecl); t; t = TREE_CHAIN (t)) - DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX; - } - - if (DECL_STATIC_CONSTRUCTOR (fndecl)) - static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors); - if (DECL_STATIC_DESTRUCTOR (fndecl)) - static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors); - + /* Clean up. */ if (! nested) - { - /* Let the error reporting routines know that we're outside a - function. For a nested function, this value is used in - pop_cp_function_context and then reset via pop_function_context. */ - current_function_decl = NULL_TREE; - } + /* Let the error reporting routines know that we're outside a + function. For a nested function, this value is used in + pop_cp_function_context and then reset via pop_function_context. */ + current_function_decl = NULL_TREE; - named_label_uses = NULL; - current_class_ptr = NULL_TREE; - current_class_ref = NULL_TREE; + return fndecl; } /* Create the FUNCTION_DECL for a function definition. @@ -14682,12 +14305,15 @@ start_method (declspecs, declarator, attrlist) tree declarator, declspecs, attrlist; { tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, - attrlist); + &attrlist); /* Something too ugly to handle. */ if (fndecl == NULL_TREE) return NULL_TREE; + if (attrlist) + cplus_decl_attributes (&fndecl, attrlist, 0); + /* Pass friends other than inline friend functions back. */ if (fndecl == void_type_node) return fndecl; @@ -14696,24 +14322,21 @@ start_method (declspecs, declarator, attrlist) /* Not a function, tell parser to report parse error. */ return NULL_TREE; - if (IS_SIGNATURE (current_class_type)) - IS_DEFAULT_IMPLEMENTATION (fndecl) = 1; - if (DECL_IN_AGGR_P (fndecl)) { if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) { - if (DECL_CONTEXT (fndecl) + if (DECL_CONTEXT (fndecl) && TREE_CODE( DECL_CONTEXT (fndecl)) != NAMESPACE_DECL) - cp_error ("`%D' is already defined in class %s", fndecl, - TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); + error ("`%D' is already defined in class `%T'", fndecl, + DECL_CONTEXT (fndecl)); } return void_type_node; } check_template_shadow (fndecl); - DECL_THIS_INLINE (fndecl) = 1; + DECL_DECLARED_INLINE_P (fndecl) = 1; if (flag_default_inline) DECL_INLINE (fndecl) = 1; @@ -14722,12 +14345,6 @@ start_method (declspecs, declarator, attrlist) if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl)) fndecl = push_template_decl (fndecl); - /* We read in the parameters on the maybepermanent_obstack, - but we won't be getting back to them until after we - may have clobbered them. So the call to preserve_data - will keep them safe. */ - preserve_data (); - if (! DECL_FRIEND_P (fndecl)) { if (TREE_CHAIN (fndecl)) @@ -14735,22 +14352,15 @@ start_method (declspecs, declarator, attrlist) fndecl = copy_node (fndecl); TREE_CHAIN (fndecl) = NULL_TREE; } - - if (DECL_CONSTRUCTOR_P (fndecl)) - { - if (! grok_ctor_properties (current_class_type, fndecl)) - return void_type_node; - } - else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) - grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0); + grok_special_member_properties (fndecl); } - cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0); + cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0); /* Make a place for the parms */ pushlevel (0); current_binding_level->parm_flag = 1; - + DECL_IN_AGGR_P (fndecl) = 1; return fndecl; } @@ -14799,8 +14409,8 @@ finish_method (decl) DECL_CONTEXT (link) = NULL_TREE; } - GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, - (HOST_WIDE_INT) current_binding_level->level_chain, + GNU_xref_end_scope ((size_t) current_binding_level, + (size_t) current_binding_level->level_chain, current_binding_level->parm_flag, current_binding_level->keep); @@ -14830,63 +14440,80 @@ hack_incomplete_structures (type) tree type; { tree *list; - - if (current_binding_level->incomplete == NULL_TREE) - return; + struct binding_level *level; if (!type) /* Don't do this for class templates. */ return; - for (list = ¤t_binding_level->incomplete; *list; ) - { - tree decl = TREE_VALUE (*list); - if ((decl && TREE_TYPE (decl) == type) - || (TREE_TYPE (decl) - && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE - && TREE_TYPE (TREE_TYPE (decl)) == type)) - { - int toplevel = toplevel_bindings_p (); - if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE - && TREE_TYPE (TREE_TYPE (decl)) == type) - layout_type (TREE_TYPE (decl)); - layout_decl (decl, 0); - rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); - if (! toplevel) + if (namespace_bindings_p ()) + { + level = 0; + list = &namespace_scope_incomplete; + } + else + { + level = innermost_nonclass_level (); + list = &level->incomplete; + } + + while (1) + { + while (*list) + { + tree decl = TREE_VALUE (*list); + if ((decl && TREE_TYPE (decl) == type) + || (TREE_TYPE (decl) + && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE + && TREE_TYPE (TREE_TYPE (decl)) == type)) { - tree cleanup; - expand_decl (decl); - cleanup = maybe_build_cleanup (decl); - expand_decl_init (decl); - if (! expand_decl_cleanup (decl, cleanup)) - cp_error ("parser lost in parsing declaration of `%D'", - decl); + int toplevel = toplevel_bindings_p (); + if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE + && TREE_TYPE (TREE_TYPE (decl)) == type) + layout_type (TREE_TYPE (decl)); + layout_decl (decl, 0); + rest_of_decl_compilation (decl, NULL, toplevel, 0); + if (! toplevel) + { + tree cleanup; + expand_decl (decl); + cleanup = maybe_build_cleanup (decl); + expand_decl_init (decl); + if (! expand_decl_cleanup (decl, cleanup)) + error ("parser lost in parsing declaration of `%D'", + decl); + } + *list = TREE_CHAIN (*list); } - *list = TREE_CHAIN (*list); + else + list = &TREE_CHAIN (*list); + } + + /* Keep looking through artificial binding levels generated + for local variables. */ + if (level && level->keep == 2) + { + level = level->level_chain; + list = &level->incomplete; } else - list = &TREE_CHAIN (*list); + break; } } -/* If DECL is of a type which needs a cleanup, build that cleanup here. - See build_delete for information about AUTO_DELETE. - - Don't build these on the momentary obstack; they must live - the life of the binding contour. */ +/* If DECL is of a type which needs a cleanup, build that cleanup + here. */ -static tree -maybe_build_cleanup_1 (decl, auto_delete) - tree decl, auto_delete; +tree +maybe_build_cleanup (decl) + tree decl; { tree type = TREE_TYPE (decl); - if (type != error_mark_node && TYPE_NEEDS_DESTRUCTOR (type)) + + if (type != error_mark_node && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) { - int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; + int flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; tree rval; - if (TREE_CODE (decl) != PARM_DECL) - temp = suspend_momentary (); - if (TREE_CODE (type) == ARRAY_TYPE) rval = decl; else @@ -14900,268 +14527,242 @@ maybe_build_cleanup_1 (decl, auto_delete) || flag_expensive_optimizations) flags |= LOOKUP_NONVIRTUAL; - rval = build_delete (TREE_TYPE (rval), rval, auto_delete, flags, 0); + rval = build_delete (TREE_TYPE (rval), rval, + sfk_complete_destructor, flags, 0); if (TYPE_USES_VIRTUAL_BASECLASSES (type) && ! TYPE_HAS_DESTRUCTOR (type)) - rval = build_compound_expr (expr_tree_cons (NULL_TREE, rval, - build_expr_list (NULL_TREE, build_vbase_delete (type, decl)))); - - if (TREE_CODE (decl) != PARM_DECL) - resume_momentary (temp); + rval = build_compound_expr (tree_cons (NULL_TREE, rval, + build_tree_list (NULL_TREE, build_vbase_delete (type, decl)))); return rval; } return 0; } + +/* When a stmt has been parsed, this function is called. */ -/* If DECL is of a type which needs a cleanup, build that cleanup - here. The cleanup does free the storage with a call to delete. */ - -tree -maybe_build_cleanup_and_delete (decl) - tree decl; +void +finish_stmt () { - return maybe_build_cleanup_1 (decl, integer_three_node); + /* Always assume this statement was not an expression statement. If + it actually was an expression statement, its our callers + responsibility to fix this up. */ + last_expr_type = NULL_TREE; } -/* If DECL is of a type which needs a cleanup, build that cleanup - here. The cleanup does not free the storage with a call a delete. */ +/* DECL was originally constructed as a non-static member function, + but turned out to be static. Update it accordingly. */ -tree -maybe_build_cleanup (decl) +void +revert_static_member_fn (decl) tree decl; { - return maybe_build_cleanup_1 (decl, integer_two_node); + tree tmp; + tree function = TREE_TYPE (decl); + tree args = TYPE_ARG_TYPES (function); + + if (cp_type_quals (TREE_TYPE (TREE_VALUE (args))) + != TYPE_UNQUALIFIED) + error ("static member function `%#D' declared with type qualifiers", + decl); + + args = TREE_CHAIN (args); + tmp = build_function_type (TREE_TYPE (function), args); + tmp = build_qualified_type (tmp, cp_type_quals (function)); + tmp = build_exception_variant (tmp, + TYPE_RAISES_EXCEPTIONS (function)); + TREE_TYPE (decl) = tmp; + if (DECL_ARGUMENTS (decl)) + DECL_ARGUMENTS (decl) = TREE_CHAIN (DECL_ARGUMENTS (decl)); + DECL_STATIC_FUNCTION_P (decl) = 1; } - -/* Expand a C++ expression at the statement level. - This is needed to ferret out nodes which have UNKNOWN_TYPE. - The C++ type checker should get all of these out when - expressions are combined with other, type-providing, expressions, - leaving only orphan expressions, such as: - &class::bar; / / takes its address, but does nothing with it. */ +/* Initialize the variables used during compilation of a C++ + function. */ -void -cplus_expand_expr_stmt (exp) - tree exp; +static void +push_cp_function_context (f) + struct function *f; { - if (processing_template_decl) - { - add_tree (build_min_nt (EXPR_STMT, exp)); - return; - } + struct cp_language_function *p + = ((struct cp_language_function *) + xcalloc (1, sizeof (struct cp_language_function))); + f->language = (struct language_function *) p; - /* Arrange for all temps to disappear. */ - expand_start_target_temps (); + /* It takes an explicit call to expand_body to generate RTL for a + function. */ + expanding_p = 0; - exp = require_complete_type_in_void (exp); - - if (TREE_CODE (exp) == FUNCTION_DECL) + /* Whenever we start a new function, we destroy temporaries in the + usual way. */ + current_stmt_tree ()->stmts_are_full_exprs_p = 1; +} + +/* Free the language-specific parts of F, now that we've finished + compiling the function. */ + +static void +pop_cp_function_context (f) + struct function *f; +{ + if (f->language) { - cp_warning ("reference, not call, to function `%D'", exp); - warning ("at this point in file"); + struct cp_language_function *cp = + (struct cp_language_function *) f->language; + if (cp->x_local_names) + VARRAY_FREE (cp->x_local_names); + free (f->language); } + f->language = 0; +} -#if 0 - /* We should do this eventually, but right now this causes regex.o from - libg++ to miscompile, and tString to core dump. */ - exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp); -#endif +/* Mark P for GC. */ + +static void +mark_lang_function (p) + struct cp_language_function *p; +{ + if (!p) + return; - /* Strip unused implicit INDIRECT_REFs of references. */ - if (TREE_CODE (exp) == INDIRECT_REF - && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE) - exp = TREE_OPERAND (exp, 0); + mark_c_language_function (&p->base); - /* If we don't do this, we end up down inside expand_expr - trying to do TYPE_MODE on the ERROR_MARK, and really - go outside the bounds of the type. */ - if (exp != error_mark_node) - expand_expr_stmt (break_out_cleanups (exp)); + ggc_mark_tree (p->x_dtor_label); + ggc_mark_tree (p->x_current_class_ptr); + ggc_mark_tree (p->x_current_class_ref); + ggc_mark_tree (p->x_eh_spec_block); + ggc_mark_tree_varray (p->x_local_names); - /* Clean up any pending cleanups. This happens when a function call - returns a cleanup-needing value that nobody uses. */ - expand_end_target_temps (); + mark_named_label_lists (&p->x_named_labels, &p->x_named_label_uses); + mark_binding_level (&p->bindings); + mark_pending_inlines (&p->unparsed_inlines); } -/* When a stmt has been parsed, this function is called. - - Currently, this function only does something within a - constructor's scope: if a stmt has just assigned to this, - and we are in a derived class, we call `emit_base_init'. */ +/* Mark the language-specific data in F for GC. */ -void -finish_stmt () +static void +mark_cp_function_context (f) + struct function *f; { - extern struct nesting *cond_stack, *loop_stack, *case_stack; - - - if (current_function_assigns_this - || ! current_function_just_assigned_this) - return; - if (DECL_CONSTRUCTOR_P (current_function_decl)) - { - /* Constructors must wait until we are out of control - zones before calling base constructors. */ - if (cond_stack || loop_stack || case_stack) - return; - expand_expr_stmt (base_init_expr); - check_base_init (current_class_type); - } - current_function_assigns_this = 1; + mark_lang_function ((struct cp_language_function *) f->language); } -/* Change a static member function definition into a FUNCTION_TYPE, instead - of the METHOD_TYPE that we create when it's originally parsed. - - WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES - (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of - other decls. Either pass the addresses of local variables or NULL. */ - void -revert_static_member_fn (decl, fn, argtypes) - tree *decl, *fn, *argtypes; +lang_mark_tree (t) + tree t; { - tree tmp; - tree function = fn ? *fn : TREE_TYPE (*decl); - tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function); - - if (CP_TYPE_QUALS (TREE_TYPE (TREE_VALUE (args))) - != TYPE_UNQUALIFIED) - cp_error ("static member function `%#D' declared with type qualifiers", - *decl); - - args = TREE_CHAIN (args); - tmp = build_function_type (TREE_TYPE (function), args); - tmp = build_qualified_type (tmp, CP_TYPE_QUALS (function)); - tmp = build_exception_variant (tmp, - TYPE_RAISES_EXCEPTIONS (function)); - TREE_TYPE (*decl) = tmp; - if (DECL_ARGUMENTS (*decl)) - DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl)); - DECL_STATIC_FUNCTION_P (*decl) = 1; - if (fn) - *fn = tmp; - if (argtypes) - *argtypes = args; -} - -struct cp_function -{ - int returns_value; - int returns_null; - int assigns_this; - int just_assigned_this; - int parms_stored; - int temp_name_counter; - tree named_labels; - struct named_label_list *named_label_uses; - tree shadowed_labels; - tree ctor_label; - tree dtor_label; - rtx last_dtor_insn; - rtx last_parm_cleanup_insn; - tree base_init_list; - tree member_init_list; - tree base_init_expr; - tree current_class_ptr; - tree current_class_ref; - rtx result_rtx; - struct cp_function *next; - struct binding_level *binding_level; - int static_labelno; -}; + enum tree_code code = TREE_CODE (t); + if (code == IDENTIFIER_NODE) + { + struct lang_identifier *li = (struct lang_identifier *) t; + struct lang_id2 *li2 = li->x; + ggc_mark_tree (li->namespace_bindings); + ggc_mark_tree (li->bindings); + ggc_mark_tree (li->class_value); + ggc_mark_tree (li->class_template_info); -static struct cp_function *cp_function_chain; + if (li2) + { + ggc_mark_tree (li2->label_value); + ggc_mark_tree (li2->implicit_decl); + ggc_mark_tree (li2->error_locus); + } + } + else if (code == CPLUS_BINDING) + { + if (BINDING_HAS_LEVEL_P (t)) + mark_binding_level (&BINDING_LEVEL (t)); + else + ggc_mark_tree (BINDING_SCOPE (t)); + ggc_mark_tree (BINDING_VALUE (t)); + } + else if (code == OVERLOAD) + ggc_mark_tree (OVL_FUNCTION (t)); + else if (code == TEMPLATE_PARM_INDEX) + ggc_mark_tree (TEMPLATE_PARM_DECL (t)); + else if (TREE_CODE_CLASS (code) == 'd') + { + struct lang_decl *ld = DECL_LANG_SPECIFIC (t); + + if (ld) + { + ggc_mark (ld); + c_mark_lang_decl (&ld->decl_flags.base); + if (!DECL_GLOBAL_CTOR_P (t) + && !DECL_GLOBAL_DTOR_P (t) + && !DECL_THUNK_P (t) + && !DECL_DISCRIMINATOR_P (t)) + ggc_mark_tree (ld->decl_flags.u2.access); + else if (DECL_THUNK_P (t)) + ggc_mark_tree (ld->decl_flags.u2.vcall_offset); + if (TREE_CODE (t) != NAMESPACE_DECL) + ggc_mark_tree (ld->decl_flags.u.template_info); + else + mark_binding_level (&NAMESPACE_LEVEL (t)); + if (CAN_HAVE_FULL_LANG_DECL_P (t)) + { + ggc_mark_tree (ld->befriending_classes); + ggc_mark_tree (ld->context); + ggc_mark_tree (ld->cloned_function); + if (TREE_CODE (t) == TYPE_DECL) + ggc_mark_tree (ld->u.sorted_fields); + else if (TREE_CODE (t) == FUNCTION_DECL + && !DECL_PENDING_INLINE_P (t)) + mark_lang_function (DECL_SAVED_FUNCTION_DATA (t)); + } + } + } + else if (TREE_CODE_CLASS (code) == 't') + { + struct lang_type *lt = TYPE_LANG_SPECIFIC (t); -extern int temp_name_counter; + if (lt && !(TREE_CODE (t) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE)) + { + ggc_mark (lt); + ggc_mark_tree (lt->primary_base); + ggc_mark_tree (lt->vfields); + ggc_mark_tree (lt->vbases); + ggc_mark_tree (lt->tags); + ggc_mark_tree (lt->size); + ggc_mark_tree (lt->pure_virtuals); + ggc_mark_tree (lt->friend_classes); + ggc_mark_tree (lt->rtti); + ggc_mark_tree (lt->methods); + ggc_mark_tree (lt->template_info); + ggc_mark_tree (lt->befriending_classes); + } + else if (lt) + /* In the case of pointer-to-member function types, the + TYPE_LANG_SPECIFIC is really just a tree. */ + ggc_mark_tree ((tree) lt); + } +} -/* Save and reinitialize the variables - used during compilation of a C++ function. */ +/* Return the IDENTIFIER_GLOBAL_VALUE of T, for use in common code, since + the definition of IDENTIFIER_GLOBAL_VALUE is different for C and C++. */ -void -push_cp_function_context (context) - tree context; +tree +identifier_global_value (t) + tree t; { - struct cp_function *p - = (struct cp_function *) xmalloc (sizeof (struct cp_function)); - - push_function_context_to (context); - - p->next = cp_function_chain; - cp_function_chain = p; - - p->named_labels = named_labels; - p->named_label_uses = named_label_uses; - p->shadowed_labels = shadowed_labels; - p->returns_value = current_function_returns_value; - p->returns_null = current_function_returns_null; - p->binding_level = current_binding_level; - p->ctor_label = ctor_label; - p->dtor_label = dtor_label; - p->last_dtor_insn = last_dtor_insn; - p->last_parm_cleanup_insn = last_parm_cleanup_insn; - p->assigns_this = current_function_assigns_this; - p->just_assigned_this = current_function_just_assigned_this; - p->parms_stored = current_function_parms_stored; - p->result_rtx = original_result_rtx; - p->base_init_expr = base_init_expr; - p->temp_name_counter = temp_name_counter; - p->base_init_list = current_base_init_list; - p->member_init_list = current_member_init_list; - p->current_class_ptr = current_class_ptr; - p->current_class_ref = current_class_ref; - p->static_labelno = static_labelno; -} - -/* Restore the variables used during compilation of a C++ function. */ + return IDENTIFIER_GLOBAL_VALUE (t); +} -void -pop_cp_function_context (context) - tree context; +/* Build the void_list_node (void_type_node having been created). */ +tree +build_void_list_node () { - struct cp_function *p = cp_function_chain; - tree link; - - /* Bring back all the labels that were shadowed. */ - for (link = shadowed_labels; link; link = TREE_CHAIN (link)) - if (DECL_NAME (TREE_VALUE (link)) != 0) - SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), - TREE_VALUE (link)); - - pop_function_context_from (context); - - cp_function_chain = p->next; - - named_labels = p->named_labels; - named_label_uses = p->named_label_uses; - shadowed_labels = p->shadowed_labels; - current_function_returns_value = p->returns_value; - current_function_returns_null = p->returns_null; - current_binding_level = p->binding_level; - ctor_label = p->ctor_label; - dtor_label = p->dtor_label; - last_dtor_insn = p->last_dtor_insn; - last_parm_cleanup_insn = p->last_parm_cleanup_insn; - current_function_assigns_this = p->assigns_this; - current_function_just_assigned_this = p->just_assigned_this; - current_function_parms_stored = p->parms_stored; - original_result_rtx = p->result_rtx; - base_init_expr = p->base_init_expr; - temp_name_counter = p->temp_name_counter; - current_base_init_list = p->base_init_list; - current_member_init_list = p->member_init_list; - current_class_ptr = p->current_class_ptr; - current_class_ref = p->current_class_ref; - static_labelno = p->static_labelno; - - free (p); + tree t = build_tree_list (NULL_TREE, void_type_node); + TREE_PARMLIST (t) = 1; + return t; } -int -in_function_p () +static int +cp_missing_noreturn_ok_p (decl) + tree decl; { - return function_depth != 0; + /* A missing noreturn is ok for the `main' function. */ + return DECL_MAIN_P (decl); } |