re PR c++/70323 (missing error on integer overflow in constexpr function result conve...
authorJakub Jelinek <jakub@redhat.com>
Wed, 23 Mar 2016 18:45:26 +0000 (19:45 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 23 Mar 2016 18:45:26 +0000 (19:45 +0100)
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

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

index 8b3918bc0ca5ec5f62729bc9767daf6ccc70813f..b7a1f3984b1f264c65799cdbf2a175fc8b36ef75 100644 (file)
@@ -1,5 +1,9 @@
 2016-03-23  Jakub Jelinek  <jakub@redhat.com>
 
+       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.
index d71e488d5e09c23d646c0721771ab35e4dc1cc5e..4baf11445df67da23f64cdd486d89cd1d888ff94 100644 (file)
@@ -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;
     }
 
index 4d620748c1b7685093cdba28e62d368d5d9f87db..8fbd1e865114771ae28d898dd2f1c3c79952bdc8 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/70323
+       * g++.dg/cpp0x/constexpr-70323.C: New test.
+
 2016-03-23  Alexandre Oliva  <aoliva@redhat.com>
            Jason Merrill  <jason@redhat.com>
            Jakub Jelinek  <jakub@redhat.com>
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C
new file mode 100644 (file)
index 0000000..8307ac8
--- /dev/null
@@ -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" }