re PR c++/47504 ([C++0x] some constexpr calculations erroneously overflow when using...
authorJason Merrill <jason@redhat.com>
Thu, 17 Mar 2011 22:00:47 +0000 (18:00 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 17 Mar 2011 22:00:47 +0000 (18:00 -0400)
PR c++/47504
* semantics.c (cxx_eval_constant_expression) [NOP_EXPR]: Don't let
the conversion set TREE_OVERFLOW.

From-SVN: r171116

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

index f710f7a7c6d30ad1df1dff93a109d1d9145b9200..51535f5168bc91f862210f316b66d2f609d027f5 100644 (file)
@@ -1,5 +1,9 @@
 2011-03-17  Jason Merrill  <jason@redhat.com>
 
+       PR c++/47504
+       * semantics.c (cxx_eval_constant_expression) [NOP_EXPR]: Don't let
+       the conversion set TREE_OVERFLOW.
+
        Core 1212
        * semantics.c (finish_decltype_type): Return T&& for xvalue.
        * typeck.c (unlowered_expr_type): Preserve cv-quals.
index cafca56fbba50e581df672023bb7818e47e28f04..b6d1008b490dce728fa2a31427a3e247d14bbdaa 100644 (file)
@@ -6991,6 +6991,11 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t,
             conversion.  */
          return fold (t);
        r = fold_build1 (TREE_CODE (t), to, op);
+       /* Conversion of an out-of-range value has implementation-defined
+          behavior; the language considers it different from arithmetic
+          overflow, which is undefined.  */
+       if (TREE_OVERFLOW_P (r) && !TREE_OVERFLOW_P (op))
+         TREE_OVERFLOW (r) = false;
       }
       break;
 
index e0b94d48b2b50c08d3911258f8ed3e5518bb3e18..c72c0e48cd1eacc896948fc9e1b1772909d7a60b 100644 (file)
@@ -1,3 +1,8 @@
+2011-03-17  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/constexpr-overflow2.C: New.
+       * g++.dg/cpp0x/constexpr-data2.C: Remove FIXME.
+
 2011-03-17  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/specs/elab2.ads: New test.
index 598cae6a44fb3dd4e87dbf832eaef4dd5dda0303..2d614ec32edacc3dd8a474ba29d1d44d006c34f7 100644 (file)
@@ -44,5 +44,4 @@ extern template struct A3<int, 510>;
 
 // Use.
 A3<int, 1111> a31;
-// FIXME should this be an error?
 A3<char, 9999> a32;            // { dg-warning "overflow" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-overflow2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-overflow2.C
new file mode 100644 (file)
index 0000000..5d5749c
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/47504
+// { dg-options -std=c++0x }
+
+char constexpr sub(char arg)
+{ return char(arg - char(1)); }
+
+int main()
+{ static char constexpr m = sub(-1); }