public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [C++ PATCH] Fix OBJ_TYPE_REF constexpr handling (PR c++/92695)
Date: Mon, 02 Dec 2019 19:10:00 -0000	[thread overview]
Message-ID: <4fd03a79-36c6-5289-f868-2e3c784a6026@redhat.com> (raw)
In-Reply-To: <20191127234443.GF10088@tucnak>

On 11/27/19 6:44 PM, Jakub Jelinek wrote:
> Hi!
> 
> On the following testcase the constexpr evaluation of the virtual call
> fails, because what cxx_eval_constant_expression returns for
> OBJ_TYPE_REF_OBJECT is actually not ADDR_EXPR, but ADDR_EXPR wrapped in
> a NOP_EXPR.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK.

> 2019-11-27  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/92695
> 	* constexpr.c (cxx_eval_constant_expression) <case OBJ_TYPE_REF>: Use
> 	STRIP_NOPS before checking for ADDR_EXPR.
> 
> 	* g++.dg/cpp2a/constexpr-virtual15.C: New test.
> 
> --- gcc/cp/constexpr.c.jj	2019-11-27 17:53:37.477566346 +0100
> +++ gcc/cp/constexpr.c	2019-11-27 21:16:51.094188509 +0100
> @@ -5566,6 +5566,7 @@ cxx_eval_constant_expression (const cons
>   	tree obj = OBJ_TYPE_REF_OBJECT (t);
>   	obj = cxx_eval_constant_expression (ctx, obj, lval, non_constant_p,
>   					    overflow_p);
> +	STRIP_NOPS (obj);
>   	/* We expect something in the form of &x.D.2103.D.2094; get x. */
>   	if (TREE_CODE (obj) != ADDR_EXPR
>   	    || !DECL_P (get_base_address (TREE_OPERAND (obj, 0))))
> --- gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C.jj	2019-11-27 21:18:15.418895652 +0100
> +++ gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C	2019-11-27 21:17:48.602306802 +0100
> @@ -0,0 +1,7 @@
> +// PR c++/92695
> +// { dg-do compile { target c++2a } }
> +
> +struct A { virtual int get() = 0; };
> +struct B : A { constexpr int get() override { return 10; } };
> +struct D { B b[2]; A* c{&(b[0])}; };
> +static_assert(D{}.c->get() == 10);
> 
> 	Jakub
> 

      parent reply	other threads:[~2019-12-02 19:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27 23:54 Jakub Jelinek
2019-11-28  0:13 ` Marek Polacek
2019-12-02 19:10 ` Jason Merrill [this message]

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=4fd03a79-36c6-5289-f868-2e3c784a6026@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@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).