I'm not sure why this wasn't showing up on x86_64-linux, but here's a
fix. When we lower SIZEOF_EXPR during genericization, we don't then
fold the containing expression, so the constexpr evaluator shouldn't
assume that everything has been folded.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 1c056fd82cc25ac0ec30be50b37f274c6ba0e496
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Nov 18 15:18:57 2014 -0500
PR c++/63940
* constexpr.c (cxx_eval_binary_expression): Don't assume the
expression was already folded.
(cxx_eval_unary_expression): Likewise.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 5abea14..517bf23 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1461,9 +1461,17 @@ cxx_eval_unary_expression (const constexpr_ctx *ctx, tree t,
addr, non_constant_p, overflow_p,
NULL);
VERIFY_CONSTANT (arg);
- if (arg == orig_arg)
- return t;
- r = fold_build1 (TREE_CODE (t), TREE_TYPE (t), arg);
+ location_t loc = EXPR_LOCATION (t);
+ enum tree_code code = TREE_CODE (t);
+ tree type = TREE_TYPE (t);
+ r = fold_unary_loc (loc, code, type, arg);
+ if (r == NULL_TREE)
+ {
+ if (arg == orig_arg)
+ r = t;
+ else
+ r = build1_loc (loc, code, type, arg);
+ }
VERIFY_CONSTANT (r);
return r;
}
@@ -1488,9 +1496,18 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t,
allow_non_constant, addr,
non_constant_p, overflow_p, NULL);
VERIFY_CONSTANT (rhs);
- if (lhs == orig_lhs && rhs == orig_rhs)
- return t;
- r = fold_build2 (TREE_CODE (t), TREE_TYPE (t), lhs, rhs);
+
+ location_t loc = EXPR_LOCATION (t);
+ enum tree_code code = TREE_CODE (t);
+ tree type = TREE_TYPE (t);
+ r = fold_binary_loc (loc, code, type, lhs, rhs);
+ if (r == NULL_TREE)
+ {
+ if (lhs == orig_lhs && rhs == orig_rhs)
+ r = t;
+ else
+ r = build2_loc (loc, code, type, lhs, rhs);
+ }
VERIFY_CONSTANT (r);
return r;
}