Hi!

On the following testcase, the first function is cp_folded into
return i == 0 ? 2147483648(OVF): 2147483647;
The problem is that we don't diagnose then the overflow at all.
We already have code that sets *overflow_p under right conditions,
just there wasn't any permerror call.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2016-03-22  Jakub Jelinek  <ja...@redhat.com>

        PR c++/70323
        * constexpr.c (cxx_eval_constant_expression): Diagnose overflow
        on TREE_OVERFLOW constants.

        * g++.dg/cpp0x/constexpr-70323.C: New test.

--- gcc/cp/constexpr.c.jj       2016-03-22 09:05:32.000000000 +0100
+++ gcc/cp/constexpr.c  2016-03-22 10:38:58.598077573 +0100
@@ -3306,8 +3306,13 @@ cxx_eval_constant_expression (const cons
     }
   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;
     }
 
--- gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C.jj     2016-03-22 
10:42:54.093884158 +0100
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C        2016-03-22 
10:42:29.000000000 +0100
@@ -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" }

        Jakub

Reply via email to