From: Jason Merrill Date: Thu, 17 Mar 2011 22:00:47 +0000 (-0400) Subject: re PR c++/47504 ([C++0x] some constexpr calculations erroneously overflow when using... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c598e5fa54f472696d5d50e2ba4991a3cec62dd1;p=gcc.git re PR c++/47504 ([C++0x] some constexpr calculations erroneously overflow when using negative numbers) PR c++/47504 * semantics.c (cxx_eval_constant_expression) [NOP_EXPR]: Don't let the conversion set TREE_OVERFLOW. From-SVN: r171116 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f710f7a7c6d..51535f5168b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2011-03-17 Jason Merrill + 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. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index cafca56fbba..b6d1008b490 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e0b94d48b2b..c72c0e48cd1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-03-17 Jason Merrill + + * g++.dg/cpp0x/constexpr-overflow2.C: New. + * g++.dg/cpp0x/constexpr-data2.C: Remove FIXME. + 2011-03-17 Eric Botcazou * gnat.dg/specs/elab2.ads: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C index 598cae6a44f..2d614ec32ed 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C @@ -44,5 +44,4 @@ extern template struct A3; // Use. A3 a31; -// FIXME should this be an error? A3 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 index 00000000000..5d5749ce2c3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-overflow2.C @@ -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); }