re PR c++/72868 (Constexpr expressions mistreat case ranges)
authorJakub Jelinek <jakub@redhat.com>
Thu, 11 Aug 2016 15:59:53 +0000 (17:59 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 11 Aug 2016 15:59:53 +0000 (17:59 +0200)
PR c++/72868
* constexpr.c (label_matches): Handle case range expressions.

* g++.dg/cpp1y/constexpr-switch4.C: New test.

From-SVN: r239379

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/constexpr-switch4.C [new file with mode: 0644]

index 04d6aa0ccbf09f12ffc6d3316bc240c0536ca9f0..c0d246060856a7e66ee0b43fc4114a573114835f 100644 (file)
@@ -1,3 +1,8 @@
+2016-08-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/72868
+       * constexpr.c (label_matches): Handle case range expressions.
+
 2016-08-11  Jason Merrill  <jason@redhat.com>
 
        PR c++/73456
index 20c870eafbd2caa5130b022dbc2bdec23ed3462d..cb0fdeebb08644fea9a6d9afdc62a178f22d52e2 100644 (file)
@@ -3448,6 +3448,12 @@ label_matches (tree *jump_target, tree_stmt_iterator i,
        {
          if (!CASE_LOW (stmt))
            default_label = i;
+         else if (CASE_HIGH (stmt))
+           {
+             if (tree_int_cst_le (CASE_LOW (stmt), *jump_target)
+                 && tree_int_cst_le (*jump_target, CASE_HIGH (stmt)))
+               return true;
+           }
          else if (tree_int_cst_equal (*jump_target, CASE_LOW (stmt)))
            return true;
        }
index c2482f5dce21eadbf5dbebac1c6059f7139667da..bb47f76359eb8ff4d8052770e16212e802e4701d 100644 (file)
@@ -1,3 +1,8 @@
+2016-08-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/72868
+       * g++.dg/cpp1y/constexpr-switch4.C: New test.
+
 2015-08-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        * gcc.target/i386/pieces-memcpy-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-switch4.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-switch4.C
new file mode 100644 (file)
index 0000000..383bde9
--- /dev/null
@@ -0,0 +1,27 @@
+// PR c++/72868
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+constexpr int
+foo (int i)
+{
+  switch (i)
+    {
+    case 11 ... 12:
+      return 4;
+    case 0 ... 9:
+      return 3;
+    default:
+      return 7;
+    }
+}
+
+#define SA(X) static_assert((X),#X)
+SA (foo (-1) == 7);
+SA (foo (0) == 3);
+SA (foo (3) == 3);
+SA (foo (9) == 3);
+SA (foo (10) == 7);
+SA (foo (11) == 4);
+SA (foo (12) == 4);
+SA (foo (13) == 7);