commit e71736621b375d376091a50d17c0cbfb789e2536 Author: Jason Merrill Date: Thu Jun 9 13:59:04 2011 -0400 * semantics.c (maybe_constant_value): Handle overflowed input. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index bf6486b..481318e 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6902,7 +6902,8 @@ non_const_var_error (tree r) else if (CP_TYPE_VOLATILE_P (type)) inform (DECL_SOURCE_LOCATION (r), "%q#D is volatile", r); - else if (!DECL_INITIAL (r)) + else if (!DECL_INITIAL (r) + || !TREE_CONSTANT (DECL_INITIAL (r))) inform (DECL_SOURCE_LOCATION (r), "%qD was not initialized with a constant " "expression", r); @@ -7337,7 +7338,14 @@ maybe_constant_value (tree t) || type_unknown_p (t) || !potential_constant_expression (t) || value_dependent_expression_p (t)) - return t; + { + if (TREE_OVERFLOW_P (t)) + { + t = build_nop (TREE_TYPE (t), t); + TREE_CONSTANT (t) = false; + } + return t; + } r = cxx_eval_outermost_constant_expr (t, true); #ifdef ENABLE_CHECKING diff --git a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc index 83f5ce1..8aa72f2 100644 --- a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc +++ b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc @@ -51,4 +51,5 @@ test04() // { dg-error "required from here" "" { target *-*-* } 46 } // { dg-error "denominator cannot be zero" "" { target *-*-* } 268 } // { dg-error "out of range" "" { target *-*-* } 269 } -// { dg-error "overflow in constant expression" "" { target *-*-* } 109 } +// { dg-error "overflow in constant expression" "" { target *-*-* } 61 } +// { dg-prune-output "not a member" }