public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: C++ PATCH for c++/86184, rejects-valid with ?: and omitted operand
Date: Wed, 27 Jun 2018 21:47:00 -0000	[thread overview]
Message-ID: <CADzB+2kymLUeZmiPUr0Y2g+FMFq_+MGFDxE3UdOLA=zj4+U+sw@mail.gmail.com> (raw)
In-Reply-To: <20180621182231.GP15879@redhat.com>

On Thu, Jun 21, 2018 at 2:22 PM, Marek Polacek <polacek@redhat.com> wrote:
> The following testcase is rejected because, for this line:
>
>   bool b = X() ?: false;
>
> arg2 is missing and arg1 is a TARGET_EXPR.  A TARGET_EXPR is a class
> prvalue so we wrap it in a SAVE_EXPR.  Later when building 'this' we
> call build_this (SAVE_EXPR <TARGET_EXPR <...>>) which triggers lvalue_error:
>  5856       cp_lvalue_kind kind = lvalue_kind (arg);
>  5857       if (kind == clk_none)
>  5858         {
>  5859           if (complain & tf_error)
>  5860             lvalue_error (input_location, lv_addressof);
> because all SAVE_EXPRs are non-lvalue.
>
> Since
> a) cp_build_addr_expr_1 can process xvalues and class prvalues,
> b) TARGET_EXPRs are only evaluated once (gimplify_target_expr),
> I thought we could do the following.  The testcase ensures that
> with the omitted operand we only construct X once.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-06-21  Marek Polacek  <polacek@redhat.com>
>
>         PR c++/86184
>         * call.c (build_conditional_expr_1): Don't wrap TARGET_EXPRs
>         in a SAVE_EXPR.
>
>         * g++.dg/ext/cond3.C: New test.
>
> --- gcc/cp/call.c
> +++ gcc/cp/call.c
> @@ -4806,6 +4806,10 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3,
>        /* Make sure that lvalues remain lvalues.  See g++.oliva/ext1.C.  */
>        if (lvalue_p (arg1))
>         arg2 = arg1 = cp_stabilize_reference (arg1);
> +      else if (TREE_CODE (arg1) == TARGET_EXPR)
> +       /* TARGET_EXPRs are only expanded once, don't wrap it in a SAVE_EXPR,
> +          rendering it clk_none of clk_class.  */
> +       arg2 = arg1;
>        else
>         arg2 = arg1 = cp_save_expr (arg1);

How about adding the special handling in cp_save_expr rather than
here, so other callers also benefit?

OK with that change.

Jason

  parent reply	other threads:[~2018-06-27 21:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-21 18:22 Marek Polacek
2018-06-27 13:05 ` Marek Polacek
2018-06-27 21:47 ` Jason Merrill [this message]
2018-06-29 15:25   ` Marek Polacek

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+2kymLUeZmiPUr0Y2g+FMFq_+MGFDxE3UdOLA=zj4+U+sw@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).