From: Jakub Jelinek Date: Wed, 23 Mar 2016 18:45:26 +0000 (+0100) Subject: re PR c++/70323 (missing error on integer overflow in constexpr function result conve... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=61637db3f2f55a1b97e6f466be012a131bede75d;p=gcc.git re PR c++/70323 (missing error on integer overflow in constexpr function result converted to bool) PR c++/70323 * constexpr.c (cxx_eval_constant_expression): Diagnose overflow on TREE_OVERFLOW constants. * g++.dg/cpp0x/constexpr-70323.C: New test. From-SVN: r234438 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8b3918bc0ca..b7a1f3984b1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2016-03-23 Jakub Jelinek + PR c++/70323 + * constexpr.c (cxx_eval_constant_expression): Diagnose overflow + on TREE_OVERFLOW constants. + PR c++/70376 * cp-gimplify.c (genericize_omp_for_stmt): Don't walk OMP_FOR_CLAUSES for OMP_TASKLOOP here. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index d71e488d5e0..4baf11445df 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -3321,8 +3321,13 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, } if (CONSTANT_CLASS_P (t)) { - if (TREE_OVERFLOW (t) && (!flag_permissive || ctx->quiet)) - *overflow_p = true; + if (TREE_OVERFLOW (t)) + { + if (!ctx->quiet) + permerror (input_location, "overflow in constant expression"); + if (!flag_permissive || ctx->quiet) + *overflow_p = true; + } return t; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4d620748c1b..8fbd1e86511 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-03-23 Jakub Jelinek + + PR c++/70323 + * g++.dg/cpp0x/constexpr-70323.C: New test. + 2016-03-23 Alexandre Oliva Jason Merrill Jakub Jelinek diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C new file mode 100644 index 00000000000..8307ac8e0a6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C @@ -0,0 +1,10 @@ +// PR c++/70323 +// { dg-do compile { target c++11 } } + +constexpr int overflow_if_0 (int i) { return __INT_MAX__ + !i; } +constexpr int overflow_if_1 (int i) { return __INT_MAX__ + i; } + +constexpr bool i0_0 = overflow_if_0 (0); // { dg-error "overflow in constant expression" } +constexpr bool i0_1 = overflow_if_0 (1); +constexpr bool i1_0 = overflow_if_1 (0); +constexpr bool i1_1 = overflow_if_1 (1); // { dg-error "overflow in constant expression" }