From: mmitchel Date: Thu, 30 Jan 2003 16:02:58 +0000 (+0000) Subject: * class.c (check_field_decls): Only check C_TYPE_FIELDS_READONLY X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=7f77d1f0ea9fef9f6d774c621aff31a59be675b5 * class.c (check_field_decls): Only check C_TYPE_FIELDS_READONLY for class types. * cp-tree.h (C_TYPE_FIELDS_READONLY): Use a lang-specific bit rather than TYPE_LANG_FLAG_0. (TYPE_BUILT_IN): Remove. (TYPE_DEPENDENT_P): New macro. (TYPE_DEPENDENT_P_VALID): Likewise. (lang_type_class): Add fields_readonly. * decl.c (record_builtin_type): Don't set TYPE_BUILT_IN. * pt.c (dependent_type_p_r): New function, split out from ... (dependent_type_p): ... here. Memoize results. * search.c (dependent_base_p): Use dependent_type_p, not uses_template_parms. * typeck.c (build_modify_expr): Only check C_TYPE_FIELDS_READONLY for class types. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@62143 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1b00808fa83..5e6a99bf14d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,21 @@ +2003-01-30 Mark Mitchell + + * class.c (check_field_decls): Only check C_TYPE_FIELDS_READONLY + for class types. + * cp-tree.h (C_TYPE_FIELDS_READONLY): Use a lang-specific bit + rather than TYPE_LANG_FLAG_0. + (TYPE_BUILT_IN): Remove. + (TYPE_DEPENDENT_P): New macro. + (TYPE_DEPENDENT_P_VALID): Likewise. + (lang_type_class): Add fields_readonly. + * decl.c (record_builtin_type): Don't set TYPE_BUILT_IN. + * pt.c (dependent_type_p_r): New function, split out from ... + (dependent_type_p): ... here. Memoize results. + * search.c (dependent_base_p): Use dependent_type_p, not + uses_template_parms. + * typeck.c (build_modify_expr): Only check C_TYPE_FIELDS_READONLY + for class types. + 2003-01-29 Mark Mitchell * call.c (build_field_call): Use build_new_op, not build_opfncall. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 378c637a60d..f1f831c919b 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3413,7 +3413,7 @@ check_field_decls (tree t, tree *access_decls, cp_warning_at ("non-static const member `%#D' in class without a constructor", x); } /* A field that is pseudo-const makes the structure likewise. */ - else if (IS_AGGR_TYPE (type)) + else if (CLASS_TYPE_P (type)) { C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type); SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index e8d8acff0cf..087a1c0e990 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -82,13 +82,13 @@ struct diagnostic_context; 6: BINFO_ACCESS (in BINFO) Usage of TYPE_LANG_FLAG_?: - 0: C_TYPE_FIELDS_READONLY (in RECORD_TYPE or UNION_TYPE). + 0: TYPE_DEPENDENT_P 1: TYPE_HAS_CONSTRUCTOR. 2: TYPE_HAS_DESTRUCTOR. 3: TYPE_FOR_JAVA. 4: TYPE_HAS_NONTRIVIAL_DESTRUCTOR 5: IS_AGGR_TYPE. - 6: TYPE_BUILT_IN. + 6: TYPE_DEPENDENT_P_VALID Usage of DECL_LANG_FLAG_?: 0: DECL_ERROR_REPORTED (in VAR_DECL). @@ -497,7 +497,8 @@ struct tree_srcloc GTY(()) TREE_LANG_FLAG_3 (NODE) /* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is read-only. */ -#define C_TYPE_FIELDS_READONLY(TYPE) TYPE_LANG_FLAG_0 (TYPE) +#define C_TYPE_FIELDS_READONLY(TYPE) \ + (LANG_TYPE_CLASS_CHECK (TYPE)->fields_readonly) /* Store a value in that field. */ #define C_SET_EXP_ORIGINAL_CODE(EXP, CODE) \ @@ -1028,12 +1029,17 @@ enum languages { lang_c, lang_cplusplus, lang_java }; (CLASS_TYPE_P (T) || TREE_CODE (T) == ENUMERAL_TYPE) #define IS_OVERLOAD_TYPE(T) TAGGED_TYPE_P (T) -/* In a *_TYPE, nonzero means a built-in type. */ -#define TYPE_BUILT_IN(NODE) TYPE_LANG_FLAG_6 (NODE) - /* True if this a "Java" type, defined in 'extern "Java"'. */ #define TYPE_FOR_JAVA(NODE) TYPE_LANG_FLAG_3 (NODE) +/* True if this type is dependent. This predicate is only valid if + TYPE_DEPENDENT_P_VALID is true. */ +#define TYPE_DEPENDENT_P(NODE) TYPE_LANG_FLAG_0 (NODE) + +/* True if dependent_type_p has been called for this type, with the + result that TYPE_DEPENDENT_P is valid. */ +#define TYPE_DEPENDENT_P_VALID(NODE) TYPE_LANG_FLAG_6(NODE) + /* Nonzero if this type is const-qualified. */ #define CP_TYPE_CONST_P(NODE) \ ((cp_type_quals (NODE) & TYPE_QUAL_CONST) != 0) @@ -1162,6 +1168,7 @@ struct lang_type_class GTY(()) unsigned non_zero_init : 1; unsigned empty_p : 1; + unsigned fields_readonly : 1; /* When adding a flag here, consider whether or not it ought to apply to a template instance if it applies to the template. If @@ -1170,7 +1177,7 @@ struct lang_type_class GTY(()) /* There are some bits left to fill out a 32-bit word. Keep track of this by updating the size of this bitfield whenever you add or remove a flag. */ - unsigned dummy : 6; + unsigned dummy : 5; tree primary_base; tree vfields; diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9078da64ed1..e02fdd23ed0 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6071,8 +6071,6 @@ record_builtin_type (enum rid rid_index, if (name) tname = get_identifier (name); - TYPE_BUILT_IN (type) = 1; - if (tname) { tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2429f7f788e..dc2a9e28177 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -171,6 +171,7 @@ static void copy_default_args_to_explicit_spec PARAMS ((tree)); static int invalid_nontype_parm_type_p PARAMS ((tree, tsubst_flags_t)); static int eq_local_specializations (const void *, const void *); static tree template_for_substitution (tree); +static bool dependent_type_p_r (tree); static bool dependent_template_id_p (tree, tree); static tree tsubst (tree, tree, tsubst_flags_t, tree); static tree tsubst_expr (tree, tree, tsubst_flags_t, tree); @@ -11202,29 +11203,14 @@ invalid_nontype_parm_type_p (type, complain) return 1; } -/* Returns TRUE if TYPE is dependent, in the sense of - [temp.dep.type]. */ +/* Returns TRUE if TYPE is dependent, in the sense of [temp.dep.type]. + Assumes that TYPE really is a type, and not the ERROR_MARK_NODE.*/ -bool -dependent_type_p (type) - tree type; +static bool +dependent_type_p_r (tree type) { tree scope; - /* If there are no template parameters in scope, then there can't be - any dependent types. */ - if (!processing_template_decl) - return false; - - /* If the type is NULL, we have not computed a type for the entity - in question; in that case, the type is dependent. */ - if (!type) - return true; - - /* Erroneous types can be considered non-dependent. */ - if (type == error_mark_node) - return false; - /* [temp.dep.type] A type is dependent if it is: @@ -11315,6 +11301,37 @@ dependent_type_p (type) return false; } +/* Returns TRUE if TYPE is dependent, in the sense of + [temp.dep.type]. */ + +bool +dependent_type_p (tree type) +{ + /* If there are no template parameters in scope, then there can't be + any dependent types. */ + if (!processing_template_decl) + return false; + + /* If the type is NULL, we have not computed a type for the entity + in question; in that case, the type is dependent. */ + if (!type) + return true; + + /* Erroneous types can be considered non-dependent. */ + if (type == error_mark_node) + return false; + + /* If we have not already computed the appropriate value for TYPE, + do so now. */ + if (!TYPE_DEPENDENT_P_VALID (type)) + { + TYPE_DEPENDENT_P (type) = dependent_type_p_r (type); + TYPE_DEPENDENT_P_VALID (type) = 1; + } + + return TYPE_DEPENDENT_P (type); +} + /* Returns TRUE if the EXPRESSION is value-dependent. */ bool diff --git a/gcc/cp/search.c b/gcc/cp/search.c index cab3bbb9cab..952c7602794 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -2417,7 +2417,7 @@ dependent_base_p (binfo) { if (currently_open_class (TREE_TYPE (binfo))) break; - if (uses_template_parms (TREE_TYPE (binfo))) + if (dependent_type_p (TREE_TYPE (binfo))) return 1; } return 0; diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 9d11262b88c..37a07b6af8f 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5511,7 +5511,7 @@ build_modify_expr (lhs, modifycode, rhs) || TREE_CODE (TREE_TYPE (lhs)) == METHOD_TYPE /* If it's an aggregate and any field is const, then it is effectively const. */ - || (IS_AGGR_TYPE_CODE (TREE_CODE (lhstype)) + || (CLASS_TYPE_P (lhstype) && C_TYPE_FIELDS_READONLY (lhstype)))) readonly_error (lhs, "assignment", 0); @@ -6266,8 +6266,7 @@ c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line) tree type = TREE_TYPE (o[i]); if (type != error_mark_node && (CP_TYPE_CONST_P (type) - || (IS_AGGR_TYPE_CODE (TREE_CODE (type)) - && C_TYPE_FIELDS_READONLY (type)))) + || (CLASS_TYPE_P (type) && C_TYPE_FIELDS_READONLY (type)))) readonly_error (o[i], "modification by `asm'", 1); } }