From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: C++ PATCH for c++/90473 - wrong code with nullptr in default argument
Date: Tue, 13 Aug 2019 14:51:00 -0000 [thread overview]
Message-ID: <0c7c9473-53fc-c732-d0cb-8425abee968f@redhat.com> (raw)
In-Reply-To: <20190809005655.GA28284@redhat.com>
On 8/8/19 8:56 PM, Marek Polacek wrote:
> This is a wrong-code bug where we are throwing away the function call in
> the default argument here:
>
> void fn1 (void* p = (f(), nullptr)) { }
>
> and thus dropping the possible side-effects of that call to the floor.
>
> That happens because check_default_argument returns nullptr_node when it
> sees a null_ptr_cst_p argument. In this case the argument is a COMPOUND_EXPR
> "f(), nullptr" and null_ptr_cst_p returns true for it. And so the effects of
> the LHS expression of the compound expr are forgotten. Fixed as below.
>
> It's tempting to change null_ptr_cst_p to return false when it sees something
> that has TREE_SIDE_EFFECTS, but that would be wrong I think: [conv.ptr] says
> that a null pointer constant is an integer literal with value zero or a prvalue
> of type std::nullptr_t. An expression "a, b", the built-in comma expression,
> is a prvalue if 'b' is an rvalue. And so "f(), nullptr" is a prvalue of type
> std::nullptr_t.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2019-08-08 Marek Polacek <polacek@redhat.com>
>
> PR c++/90473 - wrong code with nullptr in default argument.
> * call.c (null_ptr_cst_p): Update quote from the standard.
> * decl.c (check_default_argument): Don't return nullptr when the arg
> has side-effects.
OK.
Jason
prev parent reply other threads:[~2019-08-13 14:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-09 6:05 Marek Polacek
2019-08-13 14:51 ` 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=0c7c9473-53fc-c732-d0cb-8425abee968f@redhat.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).