From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: C++ PATCH to fix rejects-valid with constexpr ctor in C++17 (PR c++/83692)
Date: Mon, 05 Feb 2018 18:45:00 -0000 [thread overview]
Message-ID: <CADzB+2k625WqxrY6bcarYOOUsGfRS6KpjVTN1j8i9M4fzckJSg@mail.gmail.com> (raw)
In-Reply-To: <20180205133752.GF2608@redhat.com>
On Mon, Feb 5, 2018 at 8:37 AM, Marek Polacek <polacek@redhat.com> wrote:
> On Fri, Feb 02, 2018 at 02:11:27PM -0500, Jason Merrill wrote:
>> On Thu, Jan 25, 2018 at 4:16 PM, Marek Polacek <polacek@redhat.com> wrote:
>> > This is a similar problem to 83116: we'd cached a constexpr call, but after a
>> > store the result had become invalid, yet we used the wrong result again when
>> > encountering the same call later. This resulted in evaluating a THROW_EXPR
>> > which doesn't work. Details in
>> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83692#c5
>> >
>> > The fix for 83116 didn't work here, because when evaluating the body of the
>> > ctor via store_init_value -> cxx_constant_value we are in STRICT, so we do
>> > cache.
>>
>> > It seems that we may no longer rely on the constexpr call table when we
>> > do cxx_eval_store_expression, because that just rewrites *valp, i.e. the
>> > value of an object. Might be too big a hammer again, but I couldn't think
>> > of how I could guard the caching of a constexpr call.
>>
>> > This doesn't manifest in C++14 because build_special_member_call in C++17 is
>> > more aggressive with copy elisions (as required by P0135 which changed how we
>> > view prvalues). In C++14 build_special_member_call produces a CALL_EXPR, so
>> > expand_default_init calls maybe_constant_init, for which STRICT is false, so
>> > we avoid caching as per 83116.
>>
>> So it sounds like the problem is using cxx_constant_value for the
>> diagnostic when it has different semantics from the
>> maybe_constant_init that follows right after. I guess we want a
>> cxx_constant_init function that is a hybrid of the two.
>
> So like the following? Thanks,
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-02-04 Marek Polacek <polacek@redhat.com>
>
> PR c++/83692
> * constexpr.c (cxx_constant_init): New function.
> * cp-tree.h (cxx_constant_init): Declare.
> * typeck2.c (store_init_value): Call cxx_constant_init instead of
> cxx_constant_value.
>
> +/* Like cxx_constant_value, but non-strict mode. */
> +
> +tree
> +cxx_constant_init (tree t, tree decl)
> +{
> + return cxx_eval_outermost_constant_expr (t, false, false, decl);
> +}
Hmm, that doesn't do the TARGET_EXPR stripping that
maybe_constant_init does. I was thinking of a version of
maybe_constant_init that passes false to allow_non_constant. Probably
by making "maybe_constant_init" and cxx_constant_init both call the
current function with an additional parameter. And then the existing
call to maybe_constant_init can move under an 'else' to avoid
redundant constexpr evaluation.
Jason
next prev parent reply other threads:[~2018-02-05 18:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-25 21:58 Marek Polacek
2018-01-25 22:37 ` Marek Polacek
2018-02-02 19:11 ` Jason Merrill
2018-02-05 13:38 ` Marek Polacek
2018-02-05 18:45 ` Jason Merrill [this message]
2018-02-16 21:10 ` Jason Merrill
2018-02-23 14:30 ` Marek Polacek
2018-02-24 1:55 ` 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=CADzB+2k625WqxrY6bcarYOOUsGfRS6KpjVTN1j8i9M4fzckJSg@mail.gmail.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--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).