]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/37389 (expected integer_cst, have error_mark in build_enumerator)
authorJakub Jelinek <jakub@redhat.com>
Tue, 9 Sep 2008 19:16:49 +0000 (21:16 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 9 Sep 2008 19:16:49 +0000 (21:16 +0200)
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

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/enum4.C [new file with mode: 0644]

index 633161543f9ec1218a5e2e690fc401d480ae122d..be42b37cbfdc6b1019c42ffc7aeea4892cebf15a 100644 (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.
index 3348d28425c1253f07fd7580a0c0631b8e7388d1..d7c70182128e48313979a3d0bce112b2c41b6aaf 100644 (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;
         }
     }
 
index 185c066b9ba95cc9fdafc8a76d9164ec551d7794..79182a476c172f48a329f30961b7a50246688cbb 100644 (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
diff --git a/gcc/testsuite/g++.dg/parse/enum4.C b/gcc/testsuite/g++.dg/parse/enum4.C
new file mode 100644 (file)
index 0000000..6a20ea9
--- /dev/null
@@ -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" }
+};