This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix error handling in build_enumerator (PR c++/37389)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Mark Mitchell <mark at codesourcery dot com>, Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 9 Sep 2008 03:46:58 -0400
- Subject: [C++ PATCH] Fix error handling in build_enumerator (PR c++/37389)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The comment in build_enumerator says "We can safely assume that the previous
value is an INTEGER_CST", but that's clearly not the case. Just a few lines
below this we set value to error_mark_node (if it overflowed) and in another
place later on value can be set to NULL in C++0x overflow case.
This patch handles those two values.
Ok for trunk/4.3?
2008-09-09 Jakub Jelinek <jakub@redhat.com>
PR c++/37389
* decl.c (build_enumerator): Handle previous value's DECL_INITIAL
being NULL or error_mark_node.
* g++.dg/parse/enum4.C: New test.
--- gcc/cp/decl.c.jj 2008-09-09 09:31:02.000000000 +0200
+++ gcc/cp/decl.c 2008-09-09 09:34:29.000000000 +0200
@@ -11134,21 +11134,26 @@ build_enumerator (tree name, tree value,
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 (prev_value == NULL_TREE || prev_value == error_mark_node)
+ 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
--- gcc/testsuite/g++.dg/parse/enum4.C.jj 2008-09-09 09:37:33.000000000 +0200
+++ gcc/testsuite/g++.dg/parse/enum4.C 2008-09-09 09:37:10.000000000 +0200
@@ -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" }
+};
Jakub