Commit f5d70cc0 by Jason Merrill Committed by Jason Merrill

decl.c (finish_enum): Do set the type in a template.

        * decl.c (finish_enum): Do set the type in a template. Simplify.
        * pt.c (tsubst_enum, tsubst_copy): Revert last patch.

From-SVN: r63754
parent f06e42d6
2003-03-03 Jason Merrill <jason@redhat.com>
* decl.c (finish_enum): Do set the type in a template. Simplify.
* pt.c (tsubst_enum, tsubst_copy): Revert last patch.
2003-03-03 Mark Mitchell <mark@codesourcery.com> 2003-03-03 Mark Mitchell <mark@codesourcery.com>
PR c++/9878 PR c++/9878
......
...@@ -13072,10 +13072,14 @@ finish_enum (tree enumtype) ...@@ -13072,10 +13072,14 @@ finish_enum (tree enumtype)
/* We built up the VALUES in reverse order. */ /* We built up the VALUES in reverse order. */
TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype)); TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
/* For an enum defined in a template, all further processing is /* For an enum defined in a template, just set the type of the values;
postponed until the template is instantiated. */ all further processing is postponed until the template is
instantiated. We need to set the type so that tsubst of a CONST_DECL
works. */
if (processing_template_decl) if (processing_template_decl)
{ {
for (pair = TYPE_VALUES (enumtype); pair; pair = TREE_CHAIN (pair))
TREE_TYPE (TREE_VALUE (pair)) = enumtype;
if (at_function_scope_p ()) if (at_function_scope_p ())
add_stmt (build_min (TAG_DEFN, enumtype)); add_stmt (build_min (TAG_DEFN, enumtype));
return; return;
...@@ -13083,49 +13087,46 @@ finish_enum (tree enumtype) ...@@ -13083,49 +13087,46 @@ finish_enum (tree enumtype)
if (TYPE_VALUES (enumtype)) if (TYPE_VALUES (enumtype))
{ {
/* Initialize min and max values and figure out actual values in
following 'for' loop. */
minnode = maxnode = NULL_TREE; 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)) for (pair = TYPE_VALUES (enumtype); pair; pair = TREE_CHAIN (pair))
{ {
tree decl = TREE_VALUE (pair);
tree value = DECL_INITIAL (decl);
tree value; /* [dcl.enum]: Following the closing brace of an enum-specifier,
each enumerator has the type of its enumeration. Prior to the
/* If we are going to reset type then copy node first. closing brace, the type of each enumerator is the type of its
It cannot be shared now. */ initializing value. */
if (TREE_TYPE (TREE_VALUE (pair)) != enumtype) TREE_TYPE (decl) = 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));
/* Figure out what the minimum and maximum values of the
enumerators are. */
if (!minnode) if (!minnode)
minnode = maxnode = value; minnode = maxnode = value;
else if (tree_int_cst_lt (maxnode, value)) else if (tree_int_cst_lt (maxnode, value))
maxnode = value; maxnode = value;
else if (tree_int_cst_lt (value, minnode)) else if (tree_int_cst_lt (value, minnode))
minnode = value; minnode = value;
/* 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). But first make a copy so we
don't clobber shared INTEGER_CSTs. */
if (TREE_TYPE (value) != enumtype)
{
value = DECL_INITIAL (decl) = copy_node (value);
TREE_TYPE (value) = enumtype;
} }
/* In addition, transform the TYPE_VALUES list to contain the
values, rather than the CONST_DECLs for them. */
TREE_VALUE (pair) = value;
} }
} }
else else
minnode = maxnode = integer_zero_node; minnode = maxnode = integer_zero_node;
/* Compute the number of bits require to represent all values of the /* Compute the number of bits require to represent all values of the
enumeration. We must do this before the type of MINNODE and enumeration. We must do this before the type of MINNODE and
MAXNODE are transformed, since min_precision relies on the MAXNODE are transformed, since min_precision relies on the
...@@ -13135,18 +13136,6 @@ finish_enum (tree enumtype) ...@@ -13135,18 +13136,6 @@ finish_enum (tree enumtype)
highprec = min_precision (maxnode, unsignedp); highprec = min_precision (maxnode, unsignedp);
precision = MAX (lowprec, highprec); 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'. */ /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */
TYPE_SIZE (enumtype) = NULL_TREE; TYPE_SIZE (enumtype) = NULL_TREE;
TYPE_PRECISION (enumtype) = precision; TYPE_PRECISION (enumtype) = precision;
...@@ -13241,7 +13230,6 @@ build_enumerator (tree name, tree value, tree enumtype) ...@@ -13241,7 +13230,6 @@ build_enumerator (tree name, tree value, tree enumtype)
} }
/* Remove no-op casts from the value. */ /* Remove no-op casts from the value. */
if (value)
STRIP_TYPE_NOPS (value); STRIP_TYPE_NOPS (value);
} }
......
...@@ -7143,10 +7143,6 @@ tsubst_copy (t, args, complain, in_decl) ...@@ -7143,10 +7143,6 @@ tsubst_copy (t, args, complain, in_decl)
= tsubst_aggr_type (TREE_TYPE (t), args, complain, in_decl, = tsubst_aggr_type (TREE_TYPE (t), args, complain, in_decl,
/*entering_scope=*/0); /*entering_scope=*/0);
/* Not yet available. */
if (!enum_type || enum_type == (TREE_TYPE (t)))
return t;
for (v = TYPE_VALUES (enum_type); for (v = TYPE_VALUES (enum_type);
v != NULL_TREE; v != NULL_TREE;
v = TREE_CHAIN (v)) v = TREE_CHAIN (v))
...@@ -11074,11 +11070,6 @@ tsubst_enum (tag, newtag, args) ...@@ -11074,11 +11070,6 @@ tsubst_enum (tag, newtag, args)
{ {
tree value; 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 /* Note that in a template enum, the TREE_VALUE is the
CONST_DECL, not the corresponding INTEGER_CST. */ CONST_DECL, not the corresponding INTEGER_CST. */
value = tsubst_expr (DECL_INITIAL (TREE_VALUE (e)), value = tsubst_expr (DECL_INITIAL (TREE_VALUE (e)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment