Index: cp/decl.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v retrieving revision 1.991 diff -Idpatel.pbxuser -c -3 -p -r1.991 decl.c *** cp/decl.c 17 Jan 2003 23:59:10 -0000 1.991 --- cp/decl.c 28 Jan 2003 19:05:00 -0000 *************** finish_enum (tree enumtype) *** 13065,13079 **** /* 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 an enum defined in a template, all further processing is postponed until the template is instantiated. */ if (processing_template_decl) --- 13065,13070 ---- *************** finish_enum (tree enumtype) *** 13083,13113 **** return; } - /* Figure out what the minimum and maximum values of the enumerators - are. */ if (TYPE_VALUES (enumtype)) { minnode = maxnode = NULL_TREE; ! for (pair = TYPE_VALUES (enumtype); ! pair; ! pair = TREE_CHAIN (pair)) { tree value; ! value = DECL_INITIAL (TREE_VALUE (pair)); ! 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 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 --- 13074,13124 ---- return; } if (TYPE_VALUES (enumtype)) { + /* Initialize min and max values and figure out actual values in + following 'for' loop. */ minnode = maxnode = NULL_TREE; ! /* [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 value; ! /* If we are going to rest type then copy node first. ! It can not be shared now. */ ! if (TREE_TYPE (TREE_VALUE (pair)) != enumtype) ! { ! if (DECL_INITIAL (TREE_VALUE (pair))) ! DECL_INITIAL (TREE_VALUE (pair)) = ! copy_node (DECL_INITIAL (TREE_VALUE (pair))); ! TREE_TYPE (TREE_VALUE (pair)) = enumtype; ! } ! ! if (!processing_template_decl) ! { ! /* Adjust min and max value. */ ! value = DECL_INITIAL (TREE_VALUE (pair)); ! 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 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 *************** build_enumerator (tree name, tree value, *** 13203,13209 **** } /* Default based on previous value. */ ! if (value == NULL_TREE && ! processing_template_decl) { tree prev_value; --- 13214,13220 ---- } /* Default based on previous value. */ ! if (value == NULL_TREE) { tree prev_value; *************** build_enumerator (tree name, tree value, *** 13226,13248 **** /* 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; - #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. 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 (); --- 13237,13243 ---- Index: cp/pt.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v retrieving revision 1.653 diff -Idpatel.pbxuser -c -3 -p -r1.653 pt.c *** cp/pt.c 25 Jan 2003 18:02:40 -0000 1.653 --- cp/pt.c 28 Jan 2003 19:05:01 -0000 *************** tsubst_copy (t, args, complain, in_decl) *** 7149,7154 **** --- 7149,7158 ---- = tsubst_aggr_type (TREE_TYPE (t), args, complain, in_decl, /*entering_scope=*/0); + /* Not yet available. */ + if (!enum_type || enum_type == (TREE_TYPE (t))) + return t; + for (v = TYPE_VALUES (enum_type); v != NULL_TREE; v = TREE_CHAIN (v)) *************** tsubst_enum (tag, newtag, args) *** 11057,11063 **** for (e = TYPE_VALUES (tag); e; e = TREE_CHAIN (e)) { tree value; ! /* Note that in a template enum, the TREE_VALUE is the CONST_DECL, not the corresponding INTEGER_CST. */ value = tsubst_expr (DECL_INITIAL (TREE_VALUE (e)), --- 11061,11072 ---- for (e = TYPE_VALUES (tag); e; e = TREE_CHAIN (e)) { tree value; ! ! /* Copy node and set type */ ! if (DECL_INITIAL (TREE_VALUE (e))) ! DECL_INITIAL (TREE_VALUE (e)) = copy_node (DECL_INITIAL (TREE_VALUE (e))); ! TREE_TYPE (TREE_VALUE (e)) = tag; ! /* Note that in a template enum, the TREE_VALUE is the CONST_DECL, not the corresponding INTEGER_CST. */ value = tsubst_expr (DECL_INITIAL (TREE_VALUE (e)),