From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: P2280R4, Using unknown refs in constant expr [PR106650]
Date: Mon, 20 Nov 2023 16:29:33 -0500 [thread overview]
Message-ID: <fc067ce1-240b-4b1d-b27d-86f974930e0c@redhat.com> (raw)
In-Reply-To: <20231117214610.173872-1-polacek@redhat.com>
On 11/17/23 16:46, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> -- >8 --
> This patch is an attempt to implement (part of?) P2280, Using unknown
> pointers and references in constant expressions. (Note that R4 seems to
> only allow References to unknown/Accesses via this, but not Pointers to
> unknown.)
Indeed. That seems a bit arbitrary to me, but there it is.
We were rejecting the testcase before because
cxx_bind_parameters_in_call was trying to perform an lvalue->rvalue
conversion on the reference itself; this isn't really a thing in the
language, but worked to implement the reference bullet that the paper
removes. Your approach to fixing that makes sense to me.
We should do the same for VAR_DECL references, e.g.
extern int (&r)[42];
constexpr int i = array_size (r);
You also need to allow (implict or explicit) use of 'this', as in:
struct A
{
constexpr int f() { return 42; }
void g() { constexpr int i = f(); }
};
> This patch works to the extent that the test case added in [expr.const]
> works as expected, as well as the test in
> <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2280r4.html#the-this-pointer>
>
> Most importantly, the proposal makes this compile:
>
> template <typename T, size_t N>
> constexpr auto array_size(T (&)[N]) -> size_t {
> return N;
> }
>
> void check(int const (¶m)[3]) {
> constexpr auto s = array_size(param);
> static_assert (s == 3);
> }
>
> and I think it would be a pity not to have it in GCC 14.
>
> What still doesn't work (and I don't know if it should) is the test in $3.2:
>
> struct A2 { constexpr int f() { return 0; } };
> struct B2 : virtual A2 {};
> void f2(B2 &b) { constexpr int k = b.f(); }
>
> where we say
> error: '* & b' is not a constant expression
It seems like that is supposed to work, the problem is accessing the
vtable to perform the conversion. I have WIP to recognize that
conversion better in order to fix PR53288; this testcase can wait for
that fix.
Jason
next prev parent reply other threads:[~2023-11-20 21:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-17 21:46 Marek Polacek
2023-11-20 21:29 ` Jason Merrill [this message]
2023-11-29 18:56 ` [PATCH v2] " Marek Polacek
2023-11-29 20:40 ` 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=fc067ce1-240b-4b1d-b27d-86f974930e0c@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).