aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2014-11-18 21:14:49 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2014-11-18 21:14:49 +0000
commit93add516ee0d1a464c4e7d552668967e9f857099 (patch)
tree32053be0975646ad372a1ec3fc94a0c44bcf9407
parentd1f68cd8ba4f36a06a74ba74fbe6a137a43846d6 (diff)
PR c++/63940
* constexpr.c (cxx_eval_binary_expression): Don't assume the expression was already folded. (cxx_eval_unary_expression): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@217738 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/constexpr.c29
2 files changed, 30 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2e18932dc49..0759a575c9e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2014-11-18 Jason Merrill <jason@redhat.com>
+
+ PR c++/63940
+ * constexpr.c (cxx_eval_binary_expression): Don't assume the
+ expression was already folded.
+ (cxx_eval_unary_expression): Likewise.
+
2014-11-18 Marc Glisse <marc.glisse@inria.fr>
PR libstdc++/43622
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 5abea14ae39..517bf23145f 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;
}