cp-tree.h (struct lang_type): Added has_mutable flag.
authorNathan Sidwell <nathan@acm.org>
Sat, 16 Jan 1999 16:31:12 +0000 (16:31 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 16 Jan 1999 16:31:12 +0000 (11:31 -0500)
* 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
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/typeck.c

index c0daba4189e2abbe4177ea0f20826647d2772a62..32f5df1ce3848c0c1138490518631916da0ea6a9 100644 (file)
@@ -1,3 +1,14 @@
+1999-01-16  Nathan Sidwell  <nathan@acm.org>
+
+       * 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  <mark@markmitchell.com>
 
        * pt.c (process_template_parm): Ignore top-level qualifiers on
index 694ac0b22ba3ec682cae363520d1fc0670bfa43a..1688e025d2a1aeaec8d398c4bb3ce23032b143e7 100644 (file)
@@ -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)
index fccfba5fcd39cd34ba786f1a5ff82408d01b77ed..fb80e38cd3cb79298ea8ec9b41f7d855fb59397e 100644 (file)
@@ -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));
 
index 5e603b6d4804644b0534ee36851e726726daf7be..b15cec558278e1b6f5267f064d3b9339428785b4 100644 (file)
@@ -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))
index 6034ce359de04c017ba73214ccb0d65c989466ac..4fb4f593f14c8f9956339167130a79b691c702ca 100644 (file)
@@ -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);
+}