re PR c++/68362 (ICE: tree check: expected integer_cst, have nop_expr in get_val...
authorMarek Polacek <polacek@redhat.com>
Mon, 16 Nov 2015 20:16:57 +0000 (20:16 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 16 Nov 2015 20:16:57 +0000 (20:16 +0000)
PR c++/68362
* c-common.c (check_case_bounds): Fold low and high cases.

* g++.dg/delayedfold/switch-1.C: New test.

From-SVN: r230435

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/delayedfold/switch-1.C [new file with mode: 0644]

index e9851aa6ddd7f8c49dbe34e66dcb724eeb2bc7aa..3151e343a1de0ca9d6bf28bac4601dd4f2c7e916 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-16  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/68362
+       * c-common.c (check_case_bounds): Fold low and high cases.
+
 2015-11-16  Marek Polacek  <polacek@redhat.com>
 
        * c-ada-spec.c (dump_ada_template): Use RECORD_OR_UNION_TYPE_P.
index a062f81a1c35a8ca6b9fb8c692a55082a02a3884..06d857cc9706db16e5f89a7e86c577fcd84ec3f8 100644 (file)
@@ -3769,6 +3769,10 @@ check_case_bounds (location_t loc, tree type, tree orig_type,
   min_value = TYPE_MIN_VALUE (orig_type);
   max_value = TYPE_MAX_VALUE (orig_type);
 
+  /* We'll really need integer constants here.  */
+  case_low = fold (case_low);
+  case_high = fold (case_high);
+
   /* Case label is less than minimum for type.  */
   if (tree_int_cst_compare (case_low, min_value) < 0
       && tree_int_cst_compare (case_high, min_value) < 0)
index ac40be92d9d819123dde0ef1e22e38fc0e30573b..0f6a593c445692eccdeb2cef957bdf2ef5cbd2ad 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-16  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/68362
+       * g++.dg/delayedfold/switch-1.C: New test.
+
 2015-11-16  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/58027
diff --git a/gcc/testsuite/g++.dg/delayedfold/switch-1.C b/gcc/testsuite/g++.dg/delayedfold/switch-1.C
new file mode 100644 (file)
index 0000000..302da23
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/68362
+// { dg-do compile { target c++11 } }
+
+enum class A { foo };
+enum E { bar };
+
+void
+fn1 (const A a)
+{
+  switch (a)
+  case A::foo:;
+}
+
+void
+fn2 (E e)
+{
+  switch (e)
+  case bar:;
+}