OSDN Git Service

PR c++/47504
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Mar 2011 22:00:47 +0000 (22:00 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Mar 2011 22:00:47 +0000 (22:00 +0000)
* semantics.c (cxx_eval_constant_expression) [NOP_EXPR]: Don't let
the conversion set TREE_OVERFLOW.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@171116 138bc75d-0d04-0410-961f-82ee72b054a4

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 f710f7a..51535f5 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 cafca56..b6d1008 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 e0b94d4..c72c0e4 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 598cae6..2d614ec 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); }