Commit c8a66fc9 by Jason Merrill Committed by Jason Merrill

re PR c++/51489 (constexpr not working consistently)

	PR c++/51489

	* constexpr.c (cxx_eval_binary_expression): Don't VERIFY_CONSTANT
	the operands.

From-SVN: r233878
parent 7f0e23e9
2016-03-01 Jason Merrill <jason@redhat.com> 2016-03-01 Jason Merrill <jason@redhat.com>
PR c++/51489
* constexpr.c (cxx_eval_binary_expression): Don't VERIFY_CONSTANT
the operands.
PR c++/69995 PR c++/69995
* constexpr.c (cxx_eval_call_expression): Unshare arg. * constexpr.c (cxx_eval_call_expression): Unshare arg.
(cxx_eval_constant_expression) [DECL_EXPR]: Unshare init. (cxx_eval_constant_expression) [DECL_EXPR]: Unshare init.
......
...@@ -1612,15 +1612,14 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t, ...@@ -1612,15 +1612,14 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t,
tree lhs, rhs; tree lhs, rhs;
lhs = cxx_eval_constant_expression (ctx, orig_lhs, /*lval*/false, lhs = cxx_eval_constant_expression (ctx, orig_lhs, /*lval*/false,
non_constant_p, overflow_p); non_constant_p, overflow_p);
/* Don't VERIFY_CONSTANT if this might be dealing with a pointer to /* Don't VERIFY_CONSTANT here, it's unnecessary and will break pointer
a local array in a constexpr function. */ subtraction. */
bool ptr = POINTER_TYPE_P (TREE_TYPE (lhs)); if (*non_constant_p)
if (!ptr) return t;
VERIFY_CONSTANT (lhs);
rhs = cxx_eval_constant_expression (ctx, orig_rhs, /*lval*/false, rhs = cxx_eval_constant_expression (ctx, orig_rhs, /*lval*/false,
non_constant_p, overflow_p); non_constant_p, overflow_p);
if (!ptr) if (*non_constant_p)
VERIFY_CONSTANT (rhs); return t;
location_t loc = EXPR_LOCATION (t); location_t loc = EXPR_LOCATION (t);
enum tree_code code = TREE_CODE (t); enum tree_code code = TREE_CODE (t);
...@@ -1653,6 +1652,9 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t, ...@@ -1653,6 +1652,9 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t,
} }
else if (cxx_eval_check_shift_p (loc, ctx, code, type, lhs, rhs)) else if (cxx_eval_check_shift_p (loc, ctx, code, type, lhs, rhs))
*non_constant_p = true; *non_constant_p = true;
/* Don't VERIFY_CONSTANT if this might be dealing with a pointer to
a local array in a constexpr function. */
bool ptr = POINTER_TYPE_P (TREE_TYPE (lhs));
if (!ptr) if (!ptr)
VERIFY_CONSTANT (r); VERIFY_CONSTANT (r);
return r; return r;
......
// { dg-do compile { target c++14 } }
constexpr bool g()
{
int ar[4] = { 1, 2, 3, 4 };
auto e1 = ar;
auto e4 = ar+3;
return (e4-e1) == 3;
}
#define SA(X) static_assert((X),#X)
SA(g());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment