From dfffecb802681fbdb56629d3bdd96491ac660be0 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 10 Feb 2020 14:05:06 +0100 Subject: c++: Fix static initialization from <=>. Constant evaluation of genericize_spaceship produced a CONSTRUCTOR, which we then wanted to bind to a reference, which we can't do. So wrap the result in a TARGET_EXPR so we get something with an address. We also need to handle treating the result of cxx_eval_binary_expression as a glvalue for SPACESHIP_EXPR. My earlier change to add uid_sensitive to maybe_constant_value was wrong; we don't even look at the cache when manifestly_const_eval, and I failed to adjust the later call to cxx_eval_outermost_constant_expr. gcc/cp/ChangeLog 2020-02-11 Jason Merrill PR c++/93650 PR c++/90691 * constexpr.c (maybe_constant_value): Correct earlier change. (cxx_eval_binary_expression) [SPACESHIP_EXPR]: Pass lval through. * method.c (genericize_spaceship): Wrap result in TARGET_EXPR. --- gcc/cp/constexpr.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'gcc/cp/constexpr.c') diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 6495cf8..bf7a264 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2834,7 +2834,7 @@ cxx_fold_pointer_plus_expression (const constexpr_ctx *ctx, tree t, static tree cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t, - bool /*lval*/, + bool lval, bool *non_constant_p, bool *overflow_p) { tree r = NULL_TREE; @@ -2902,7 +2902,7 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t, else if (code == SPACESHIP_EXPR) { r = genericize_spaceship (type, lhs, rhs); - r = cxx_eval_constant_expression (ctx, r, false, non_constant_p, + r = cxx_eval_constant_expression (ctx, r, lval, non_constant_p, overflow_p); } @@ -6686,13 +6686,11 @@ maybe_constant_value (tree t, tree decl, bool manifestly_const_eval, r = unshare_expr_without_location (r); protected_set_expr_location (r, EXPR_LOCATION (t)); } - if (r != t || TREE_CONSTANT (t) || !manifestly_const_eval) - return r; - /* If we cached this as non-constant and we need a constant value, try - again; we might have failed before due to UID_SENSITIVE. */ + return r; } - r = cxx_eval_outermost_constant_expr (t, true, true, false, false, decl); + r = cxx_eval_outermost_constant_expr (t, true, true, false, false, + decl, uid_sensitive); gcc_checking_assert (r == t || CONVERT_EXPR_P (t) || TREE_CODE (t) == VIEW_CONVERT_EXPR -- cgit v1.1