re PR c++/70323 (missing error on integer overflow in constexpr function result conve...
authorJason Merrill <jason@redhat.com>
Thu, 24 Mar 2016 17:59:58 +0000 (13:59 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 24 Mar 2016 17:59:58 +0000 (13:59 -0400)
PR c++/70323

* constexpr.c (cxx_eval_call_expression): Don't cache result if
*overflow_p.

From-SVN: r234463

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

index dbef1b206f28b734707af1344a528afd906b4731..6512cc5b0a8a00098419ab7524284941fead05ca 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-24  Jason Merrill  <jason@redhat.com>
+
+       PR c++/70323
+       * constexpr.c (cxx_eval_call_expression): Don't cache result if
+       *overflow_p.
+
 2016-03-24  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/62212
index 8427513854d408451b1e959e3cf793f8da110a5a..2d30a84127938c150418fc0c73d74fbb789823b1 100644 (file)
@@ -1448,7 +1448,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
 
       if (result == error_mark_node)
        *non_constant_p = true;
-      if (*non_constant_p)
+      if (*non_constant_p || *overflow_p)
        result = error_mark_node;
       else if (!result)
        result = void_node;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-70323a.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-70323a.C
new file mode 100644 (file)
index 0000000..d166787
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/70323
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wall" }
+
+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" }