From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [committed] c++: Fix static initialization from <=>.
Date: Tue, 11 Feb 2020 08:18:00 -0000 [thread overview]
Message-ID: <20200211081842.18866-1-jason@redhat.com> (raw)
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.
Tested x86_64-pc-linux-gnu, applying to trunk.
gcc/cp/ChangeLog
2020-02-11 Jason Merrill <jason@redhat.com>
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 +++++-------
gcc/cp/method.c | 3 +++
gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C | 14 ++++++++++++++
3 files changed, 22 insertions(+), 7 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 6495cf88e69..bf7a2643003 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
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index fef19e18196..cfc37bc1b17 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1075,6 +1075,9 @@ genericize_spaceship (tree type, tree op0, tree op1)
comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1);
r = fold_build3 (COND_EXPR, type, comp, eq, r);
+ /* Wrap the whole thing in a TARGET_EXPR like build_conditional_expr_1. */
+ r = get_target_expr (r);
+
return r;
}
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C
new file mode 100644
index 00000000000..02f92b10aef
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C
@@ -0,0 +1,14 @@
+// PR c++/93650
+// { dg-do compile { target c++2a } }
+
+namespace std {
+ using type = enum _Ord { less };
+ class strong_ordering {
+ type _M_value;
+ constexpr strong_ordering(_Ord) : _M_value() {}
+ static const strong_ordering less;
+ static strong_ordering equal;
+ static strong_ordering greater;
+ } constexpr strong_ordering::less(_Ord::less);
+ auto v = 1 <=> 2;
+}
base-commit: a6ee556c7659877bb59b719f11ca2153e86ded59
--
2.18.1
reply other threads:[~2020-02-11 8:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200211081842.18866-1-jason@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).