re PR c++/37389 (expected integer_cst, have error_mark in build_enumerator)

PR c++/37389
	* decl.c (build_enumerator): Handle previous value's DECL_INITIAL
	being error_operand_p.  Don't clear value if it was error_mark_node.

	* g++.dg/parse/enum4.C: New test.

From-SVN: r140165
This commit is contained in:
Jakub Jelinek 2008-09-09 21:16:49 +02:00 committed by Jakub Jelinek
parent a213b2190b
commit 0f7a47dd9f
4 changed files with 37 additions and 13 deletions

View File

@ -1,3 +1,9 @@
2008-09-09 Jakub Jelinek <jakub@redhat.com>
PR c++/37389
* decl.c (build_enumerator): Handle previous value's DECL_INITIAL
being error_operand_p. Don't clear value if it was error_mark_node.
2008-09-09 Paolo Bonzini <bonzini@gnu.org>
* cp-objcp-common.h (LANG_HOOKS_EXPAND_DECL): Remove.

View File

@ -11143,21 +11143,26 @@ build_enumerator (tree name, tree value, tree enumtype)
tree prev_value;
bool overflowed;
/* The next value is the previous value plus one. We can
safely assume that the previous value is an INTEGER_CST.
/* The next value is the previous value plus one.
add_double doesn't know the type of the target expression,
so we must check with int_fits_type_p as well. */
prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
overflowed = add_double (TREE_INT_CST_LOW (prev_value),
TREE_INT_CST_HIGH (prev_value),
1, 0, &lo, &hi);
value = build_int_cst_wide (TREE_TYPE (prev_value), lo, hi);
overflowed |= !int_fits_type_p (value, TREE_TYPE (prev_value));
if (overflowed)
if (error_operand_p (prev_value))
value = error_mark_node;
else
{
error ("overflow in enumeration values at %qD", name);
value = error_mark_node;
overflowed = add_double (TREE_INT_CST_LOW (prev_value),
TREE_INT_CST_HIGH (prev_value),
1, 0, &lo, &hi);
value = build_int_cst_wide (TREE_TYPE (prev_value), lo, hi);
overflowed
|= !int_fits_type_p (value, TREE_TYPE (prev_value));
if (overflowed)
{
error ("overflow in enumeration values at %qD", name);
value = error_mark_node;
}
}
}
else
@ -11181,8 +11186,6 @@ build_enumerator (tree name, tree value, tree enumtype)
/* Silently convert the value so that we can continue. */
value = perform_implicit_conversion (ENUM_UNDERLYING_TYPE (enumtype),
value, tf_none);
if (value == error_mark_node)
value = NULL_TREE;
}
}

View File

@ -1,3 +1,8 @@
2008-09-09 Jakub Jelinek <jakub@redhat.com>
PR c++/37389
* g++.dg/parse/enum4.C: New test.
2008-09-09 Daniel Kraft <d@domob.eu>
PR fortran/37429

View File

@ -0,0 +1,10 @@
// PR c++/37389
// { dg-do compile }
// { dg-options "-std=gnu++98" }
enum
{
A = 9223372036854775807ULL * 2 + 1,
B = B0, // { dg-error "was not declared|overflow" }
C = C0 // { dg-error "was not declared" }
};