From a7a7710d423cba8feb795c3e626df5ce4075cebb Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Sat, 16 Jan 1999 16:31:12 +0000 Subject: [PATCH] cp-tree.h (struct lang_type): Added has_mutable flag. * cp-tree.h (struct lang_type): Added has_mutable flag. (CLASSTYPE_HAS_MUTABLE): New macro to access it. (TYPE_HAS_MUTABLE_P): New macro to read it. (cp_has_mutable_p): Prototype for new function. * class.c (finish_struct_1): Set has_mutable from members. * decl.c (cp_finish_decl): Clear decl's TREE_READONLY flag, if it contains a mutable. * typeck.c (cp_has_mutable_p): New function. Fixes g++.other/mutable1.C From-SVN: r24701 --- gcc/cp/ChangeLog | 11 +++++++++++ gcc/cp/class.c | 5 +++++ gcc/cp/cp-tree.h | 8 +++++++- gcc/cp/decl.c | 3 +++ gcc/cp/typeck.c | 12 ++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c0daba4..32f5df1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +1999-01-16 Nathan Sidwell + + * cp-tree.h (struct lang_type): Added has_mutable flag. + (CLASSTYPE_HAS_MUTABLE): New macro to access it. + (TYPE_HAS_MUTABLE_P): New macro to read it. + (cp_has_mutable_p): Prototype for new function. + * class.c (finish_struct_1): Set has_mutable from members. + * decl.c (cp_finish_decl): Clear decl's TREE_READONLY flag, if + it contains a mutable. + * typeck.c (cp_has_mutable_p): New function. + 1999-01-15 Mark Mitchell * pt.c (process_template_parm): Ignore top-level qualifiers on diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 694ac0b..1688e02 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3316,6 +3316,7 @@ finish_struct_1 (t, warn_anon) int cant_have_default_ctor; int cant_have_const_ctor; int no_const_asn_ref; + int has_mutable = 0; /* The index of the first base class which has virtual functions. Only applied to non-virtual baseclasses. */ @@ -3578,6 +3579,9 @@ finish_struct_1 (t, warn_anon) if (TREE_CODE (TREE_TYPE (x)) == POINTER_TYPE) has_pointers = 1; + if (DECL_MUTABLE_P (x) || TYPE_HAS_MUTABLE_P (TREE_TYPE (x))) + has_mutable = 1; + /* If any field is const, the structure type is pseudo-const. */ if (TREE_READONLY (x)) { @@ -3794,6 +3798,7 @@ finish_struct_1 (t, warn_anon) CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = const_sans_init; CLASSTYPE_REF_FIELDS_NEED_INIT (t) = ref_sans_init; CLASSTYPE_ABSTRACT_VIRTUALS (t) = abstract_virtuals; + CLASSTYPE_HAS_MUTABLE (t) = has_mutable; /* Effective C++ rule 11. */ if (has_pointers && warn_ecpp && TYPE_HAS_CONSTRUCTOR (t) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index fccfba5..fb80e38 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -726,11 +726,12 @@ struct lang_type unsigned has_abstract_assign_ref : 1; unsigned non_aggregate : 1; unsigned is_partial_instantiation : 1; + unsigned has_mutable : 1; /* The MIPS compiler gets it wrong if this struct also does not fill out to a multiple of 4 bytes. Add a member `dummy' with new bits if you go over the edge. */ - unsigned dummy : 11; + unsigned dummy : 10; } type_flags; int n_ancestors; @@ -1037,6 +1038,10 @@ struct lang_type /* Ditto, for operator=. */ #define TYPE_HAS_NONPUBLIC_ASSIGN_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_nonpublic_assign_ref) +/* Nonzero means that this type contains a mutable member */ +#define CLASSTYPE_HAS_MUTABLE(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_mutable) +#define TYPE_HAS_MUTABLE_P(NODE) (cp_has_mutable_p (NODE)) + /* Many routines need to cons up a list of basetypes for access checking. This field contains a TREE_LIST node whose TREE_VALUE is the main variant of the type, and whose TREE_VIA_PUBLIC @@ -3372,6 +3377,7 @@ extern int comp_ptr_ttypes PROTO((tree, tree)); extern int ptr_reasonably_similar PROTO((tree, tree)); extern tree build_ptrmemfunc PROTO((tree, tree, int)); extern int cp_type_quals PROTO((tree)); +extern int cp_has_mutable_p PROTO((tree)); extern int at_least_as_qualified_p PROTO((tree, tree)); extern int more_qualified_p PROTO((tree, tree)); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5e603b6..b15cec5 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7369,6 +7369,9 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) return; } + if (TYPE_HAS_MUTABLE_P (type)) + TREE_READONLY (decl) = 0; + if (processing_template_decl) { if (init && DECL_INITIAL (decl)) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 6034ce3..4fb4f59 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -7471,3 +7471,15 @@ cp_type_quals (type) return TYPE_QUALS (type); } + +/* Returns non-zero if the TYPE contains a mutable member */ + +int +cp_has_mutable_p (type) + tree type; +{ + while (TREE_CODE (type) == ARRAY_TYPE) + type = TREE_TYPE (type); + + return CLASS_TYPE_P (type) && CLASSTYPE_HAS_MUTABLE (type); +} -- 2.7.4