From 385ed708b272bb4b53aeda3081960f63ac56d7b0 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 11 Aug 2016 17:59:53 +0200 Subject: [PATCH] re PR c++/72868 (Constexpr expressions mistreat case ranges) 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 | 5 ++++ gcc/cp/constexpr.c | 6 +++++ gcc/testsuite/ChangeLog | 5 ++++ .../g++.dg/cpp1y/constexpr-switch4.C | 27 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-switch4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 04d6aa0ccbf..c0d24606085 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-08-11 Jakub Jelinek + + PR c++/72868 + * constexpr.c (label_matches): Handle case range expressions. + 2016-08-11 Jason Merrill PR c++/73456 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 20c870eafbd..cb0fdeebb08 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c2482f5dce2..bb47f76359e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-08-11 Jakub Jelinek + + PR c++/72868 + * g++.dg/cpp1y/constexpr-switch4.C: New test. + 2015-08-11 H.J. Lu * 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 index 00000000000..383bde934be --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-switch4.C @@ -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); -- 2.30.2