From: Patrick Palka <ppalka@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: Patrick Palka <ppalka@redhat.com>,
Marek Polacek <polacek@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: noexcept and copy elision [PR109030]
Date: Wed, 15 Mar 2023 19:47:32 -0400 (EDT) [thread overview]
Message-ID: <5720dde1-3aae-0fc0-44b5-2d992951c55b@idea> (raw)
In-Reply-To: <db74724c-4138-36cb-5153-68688cf3fa21@redhat.com>
On Thu, 9 Mar 2023, Jason Merrill wrote:
> On 3/9/23 14:32, Patrick Palka wrote:
> > On Mon, 6 Mar 2023, Marek Polacek via Gcc-patches wrote:
> >
> > > When processing a noexcept, constructors aren't elided: build_over_call
> > > has
> > > /* It's unsafe to elide the constructor when handling
> > > a noexcept-expression, it may evaluate to the wrong
> > > value (c++/53025). */
> > > && (force_elide || cp_noexcept_operand == 0))
> > > so the assert I added recently needs to be relaxed a little bit.
> > >
> > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> > >
> > > PR c++/109030
> > >
> > > gcc/cp/ChangeLog:
> > >
> > > * constexpr.cc (cxx_eval_call_expression): Relax assert.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > * g++.dg/cpp0x/noexcept77.C: New test.
> > > ---
> > > gcc/cp/constexpr.cc | 6 +++++-
> > > gcc/testsuite/g++.dg/cpp0x/noexcept77.C | 9 +++++++++
> > > 2 files changed, 14 insertions(+), 1 deletion(-)
> > > create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept77.C
> > >
> > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
> > > index 364695b762c..5384d0e8e46 100644
> > > --- a/gcc/cp/constexpr.cc
> > > +++ b/gcc/cp/constexpr.cc
> > > @@ -2869,7 +2869,11 @@ cxx_eval_call_expression (const constexpr_ctx *ctx,
> > > tree t,
> > > /* We used to shortcut trivial constructor/op= here, but nowadays
> > > we can only get a trivial function here with
> > > -fno-elide-constructors. */
> > > - gcc_checking_assert (!trivial_fn_p (fun) || !flag_elide_constructors);
> > > + gcc_checking_assert (!trivial_fn_p (fun)
> > > + || !flag_elide_constructors
> > > + /* We don't elide constructors when processing
> > > + a noexcept-expression. */
> > > + || cp_noexcept_operand);
> >
> > It seems weird that we're performing constant evaluation within an
> > unevaluated operand. Would it make sense to also fix this a second way
> > by avoiding constant evaluation from maybe_constant_init when
> > cp_unevaluated_operand && !manifestly_const_eval, like in
> > maybe_constant_value?
>
> Sounds good.
Hmm, while working on this I noticed we currently don't reject a version of
g++.dg/cpp2a/constexpr-inst1.C that list initializes an aggregate instead of
int (ever since r12-4425-g1595fe44e11a96):
struct A { int m; };
template<typename T> constexpr int f() { return T::value; }
template<bool B, typename T> void h(decltype(A{B ? f<T>() : 0})); // was int{...}
template<bool B, typename T> void h(...);
void x() {
h<false, int>(0); // OK?
}
ISTM we should instantiate f<int> here for the same reason we do in the
original version of the testcase, and for that to happen we need to
pass manifestly_const_eval=true in massage_init_elt. Does that seem
reasonable?
next prev parent reply other threads:[~2023-03-15 23:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-06 23:59 Marek Polacek
2023-03-07 14:55 ` Jason Merrill
2023-03-09 19:32 ` Patrick Palka
2023-03-09 23:12 ` Jason Merrill
2023-03-15 23:47 ` Patrick Palka [this message]
2023-03-16 14:09 ` Patrick Palka
2023-03-16 14:38 ` Jason Merrill
2023-03-16 15:48 ` Patrick Palka
2023-03-16 15:59 ` Jason Merrill
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=5720dde1-3aae-0fc0-44b5-2d992951c55b@idea \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=polacek@redhat.com \
/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).