public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: waffl3x <waffl3x@protonmail.com>
To: Jason Merrill <jason@redhat.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v3 1/2] c++: Initial support for P0847R7 (Deducing This) [PR102609]
Date: Fri, 20 Oct 2023 04:34:41 +0000	[thread overview]
Message-ID: <z_Np7zbsi7jPllaaPNZ3g-UPoIRGVfvJ-7WzujG1awUL4Gp8iw8PI4fTrf962fafb4GU2ikJ7C88SLWot9iO9n-iemoSSQwFFdf5v4pO7FA=@protonmail.com> (raw)
In-Reply-To: <1fdadb6b-e4ca-40c1-bb1c-43a0f42826ba@redhat.com>

> > 
> > Based on what you've said, I assume that OFFSET_REF handles static
> > member functions that are overloaded. But as I've said this seems to
> > contradict the comments I'm reading, so I'm not sure that I'm
> > understanding you correctly.
> 
> 
> That's right. For instance,
> 
> struct A {
> static void g();
> static void g(int);
> };
> 
> void (*p)(int) = &A::g; // cp_build_addr_expr_1 gets an OFFSET_REF
> 
> > > > I think we need the OFFSET_REF for an explicit-object member function
> > > > because it expresses that the code satisfies the requirement "If the
> > > > operand names an explicit object member function, the operand shall be a
> > > > qualified-id."
> > 
> > I do agree here, but it does reinforce that OFFSET_REF is no longer
> > just for members represented by pointer to member type. So that might
> > be something to take into consideration.
> 
> 
> An OFFSET_REF that isn't type_unknown_p, agreed.
> 
> > > > It might simplify things to remove the optimization in build_offset_ref
> > > > so we get an OFFSET_REF even for a single static member function, and
> > > > add support for that to cp_build_addr_expr_1.
> > 
> > I don't think this should be necessary, the "right thing" should just
> > be done for explicit-object member functions. With all the stuff going
> > on here that I missed I'm starting to wonder how function overloads
> > ever worked at all in my patch. On the other hand though, this
> > optimization probably could be documented better, but I very well might
> > have missed it even if it were.
> > 
> > Hell, maybe it needs a greater redesign altogether, it seems strange to
> > me to bundle overload information in with a construct for a specific
> > expression. (Assuming that's whats happening of course, I still don't
> > fully understand it.) It's not like this has rules unique to it for how
> > overload resolution is decided, right? Initializing a param/variable of
> > pointer to function type with an overloaded function resolves that with
> > similar rules, I think? Maybe it is a little different now that I write
> > it out loud.
> > 
> > I wasn't going to finish my musings about that, but it made me realize
> > that it might not actually be correct for address of explicit-object
> > member functions to be wrapped by OFFSET_REF. I mean surely it's fine
> > because based on what you've said static member functions are also
> > wrapped by OFFSET_REF, so it's likely fully implemented, especially
> > considering things worked before. But now that there are 2 different
> > varieties of class members that the address of them can be taken, it
> > might make sense to split things up a bit? Then again, why were static
> > member functions ever handled the same way? Taking the address of other
> > static members isn't handled in the same way here is it?
> 
> 
> Functions are different because of overloading; in general we can't
> decide what an expression that names a function actually means until we
> have enough context to decide which function, exactly. So we represent
> the id-expression largely as lookup+syntax until overload resolution
> turns it into a specific function. The type_unknown_p check earlier in
> cp_build_addr_expr_1 is for that case.

Yeah this all makes sense, but that's why I was confused by the
following documentation from cp-tree.def.

```
/* An OFFSET_REF is used in two situations:

   1. An expression of the form `A::m' where `A' is a class and `m' is
      a non-static member.  In this case, operand 0 will be a TYPE
      (corresponding to `A') and operand 1 will be a FIELD_DECL,
      BASELINK, or TEMPLATE_ID_EXPR (corresponding to `m').

      The expression is a pointer-to-member if its address is taken,
      but simply denotes a member of the object if its address is not
      taken.
```

> An OFFSET_REF that isn't type_unknown_p, agreed.
But I suppose that's what this might have been referring to.

So is that the case then? OFFSET_REF might be for a regular address of
member expression unless it's type_unknown_p?

> 
> An id-expression that names a single non-template function
> (!really_overloaded_fn) is handled somewhat differently, as we don't
> need to defer everything. But that means various special-case code.
> 
> Currently build_offset_ref special-cases &A::f for a single static
> member function, but we can't use the same special case for single
> explicit object member functions because we need to distinguish between
> &A::f and &f somehow to check the requirement I quoted above. So it
> seems to me we'll need to add support for single explicit object member
> functions in the OFFSET_REF handling in cp_build_addr_expr_1. And I
> thought if we're doing that, perhaps we want to move the single static
> handling over there as well, but that's not necessary.
> 
> Jason

I'm done for today but it does seem like that special case is what is
causing my crash. I found that it only jumps into the section that it
crashes in when there are no overloads. I'm kinda close to fixing it
probably but I've spent too long on it for today, it's melting together.

> Currently build_offset_ref special-cases &A::f for a single static
> member function, but we can't use the same special case for single
> explicit object member functions because we need to distinguish between
> &A::f and &f somehow to check the requirement I quoted above.

I don't understand what this means exactly, under what circumstances
would &f find the member function. Oh, I guess while in the body of
it's class, I hadn't considered that. Is that what you're referring to?

Well either way, I'm going to pick back up here tomorrow and see if I
can finish figuring out exactly whats causing the problems. I'm pretty
certain it's the special case that causes it, I'm just not sure what
part exactly is causing the difference, and whether there aren't more
hiding issues. But for now I need to get some rest. Thanks for the
detailed responses, they helped a lot, this part of the code has been
particularly difficult to figure out.

Alex

  reply	other threads:[~2023-10-20  4:34 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31  6:02 [PATCH " waffl3x
2023-08-31  8:33 ` Jakub Jelinek
2023-09-02  8:43   ` waffl3x
2023-09-11 13:49     ` [PATCH v2 " waffl3x
2023-09-19 20:14       ` Jason Merrill
2023-09-20  0:30         ` waffl3x
2023-09-20 21:19           ` Jason Merrill
2023-09-21 11:28             ` waffl3x
2023-09-22 11:30               ` Jason Merrill
2023-09-26  1:56                 ` [PATCH v3 " waffl3x
2023-09-27 22:43                   ` Hans-Peter Nilsson
2023-09-27 23:35                     ` Waffl3x
2023-10-17 20:53                   ` Jason Merrill
2023-10-17 21:11                   ` Jason Merrill
2023-10-18 11:46                     ` waffl3x
2023-10-18 14:17                       ` Jason Merrill
2023-10-18 17:28                         ` waffl3x
2023-10-18 17:45                           ` Jakub Jelinek
2023-10-18 18:12                           ` Jason Merrill
2023-10-19 21:05                             ` waffl3x
2023-10-19 21:11                               ` Jakub Jelinek
2023-10-19 21:31                                 ` waffl3x
2023-10-19 21:53                                   ` Jakub Jelinek
2023-10-19 22:18                               ` Jason Merrill
     [not found]                                 ` <Q2xXS2RkwtzDslDUAsi4YWupkb9s3QKvecqsxLNUr=5FL-MdSmzIJcZ96S3B9Avk30GneMm8R67JsQ4D-Uj1JB6N8dhTw6LAlNsrpLKHuLP2o=3D@protonmail.com>
2023-10-19 22:51                                 ` waffl3x
2023-10-19 23:35                                   ` waffl3x
2023-10-20  2:39                                     ` Jason Merrill
2023-10-20  4:34                                       ` waffl3x [this message]
2023-10-20 16:01                                         ` Jason Merrill
     [not found]                                           ` <zXWkSXEO=5FH62WXyNUeV1zNAx9wSVGQ5ooxKAfpN2InCP4X25uOC0yTZlnMqbDMoIa4lGwj0hP-KEP5UIcMs1S1zkhz=5FZx4oM3oz09DY2BRg=3D@protonmail.com>
     [not found]                                             ` <9YnRZJPkB8KCk8R86UDwWBoNnmOEAir4IU4enb1qIGgVdkB6dwy76ClgAzwpPqpToQ9sLTBs50EIRwhivBJU6RAFfLt-fjJxdYTZ35YVFWA=3D@protonmail.com>
2023-10-28  4:07                                           ` waffl3x
2023-10-28 23:21                                             ` waffl3x
2023-11-01 23:15                                               ` waffl3x
2023-11-02  7:01                                                 ` waffl3x
2023-11-02  7:01                                                 ` Jakub Jelinek
2023-11-03  3:04                                             ` Jason Merrill
2023-11-03  4:44                                               ` waffl3x
2023-11-03 18:05                                                 ` Jason Merrill
2023-11-04  6:40                                                   ` waffl3x
2023-11-09 18:44                                                     ` Jason Merrill
2023-11-10  4:24                                                       ` waffl3x
2023-11-10 23:12                                                         ` Jason Merrill
2023-11-11 10:43                                                           ` waffl3x
2023-11-11 11:24                                                             ` waffl3x
2023-11-14  3:48                                                             ` Jason Merrill
2023-11-14  4:36                                                               ` waffl3x
2023-11-18  6:43                                                                 ` waffl3x
2023-11-19  6:22                                                                   ` Jason Merrill
2023-11-19 13:39                                                                     ` waffl3x
2023-11-19 16:31                                                                       ` Jason Merrill
2023-11-19 18:36                                                                         ` waffl3x
2023-11-19 20:34                                                                           ` Jason Merrill
2023-11-19 21:44                                                                             ` waffl3x
2023-11-20 14:35                                                                               ` Jason Merrill
     [not found]                                                                                 ` <1MdaTybBd=5Fo4uw-Gb23fYyd5GNz7qFqoSe=5Ff5h90LY=5FBdzM2ge2qPSyCuiCLYoYcZSjmVv13fw1LmjQC=5FM2L8raS1fydY5pEJ=5Fvwvv5Z-0k=3D@protonmail.com>
2023-11-21 10:02                                                                                 ` waffl3x
2023-11-21 13:04                                                                                   ` [PATCH v5 1/1] " waffl3x
2023-11-22  3:22                                                                                     ` Jason Merrill
2023-11-22 20:46                                                                                       ` waffl3x
2023-11-22 21:38                                                                                         ` Jason Merrill
     [not found]                                                                                           ` <kltTuyDDwoyOmhBWostMKm5zF3sQCGz3HjMBrBUK6LOZp1-AbGMl5ijKKMlOncwR2yiWippyp89sFPZykNF3OVyz4yknnCVwn=5FiHJPUl25k=3D@protonmail.com>
     [not found]                                                                                             ` <dHEpSeuiljMbH0YhwLULApd3yO3LNaVkamGW2KJBYBl0EgMrtpJZ41GeTVOc77siD1kh2vkF4zwInWWGxYXfcnW4XV7sfDPX7cY028JiORE=3D@protonmail.com>
2023-11-22 21:56                                                                                           ` waffl3x
2023-11-22 22:44                                                                                           ` waffl3x
2023-11-24  6:49                                                                                             ` waffl3x
2023-11-24 23:26                                                                                               ` waffl3x
2023-11-25  1:14                                                                                                 ` waffl3x
2023-11-26 21:30                                                                                                   ` Jason Merrill
2023-11-26 23:10                                                                                                     ` waffl3x
2023-11-27  1:16                                                                                                       ` Jason Merrill
     [not found]                                                                                                         ` <BEI8PD7nktTuX7dimb22uDnR0b8Bc8ozi4xx9KbiEFj8TjgUCxMfEPpcIPL0bkdThBBab97T1uEJ9rUM3va1eiE1TyRw=5FiLrxwKgg30ZaW0=3D@protonmail.com>
2023-11-27  1:30                                                                                                         ` waffl3x
2023-11-27  1:44                                                                                                         ` waffl3x
2023-11-27  2:40                                                                                                           ` Jason Merrill
2023-11-27  5:35                                                                                                           ` [PATCH v6 " waffl3x
2023-11-28  3:31                                                                                                             ` waffl3x
2023-11-28 10:00                                                                                                               ` waffl3x
2023-11-30  5:00                                                                                                             ` Jason Merrill
2023-11-30  6:36                                                                                                               ` waffl3x
2023-11-30 14:55                                                                                                                 ` Jason Merrill
2023-12-01  6:02                                                                                                                   ` waffl3x
2023-12-01 16:52                                                                                                                     ` Jason Merrill
2023-12-02  1:31                                                                                                                       ` waffl3x
2023-12-02 15:02                                                                                                                         ` Jason Merrill
     [not found]                                                                                                                           ` <KQegse=5FguOyql4Ok1lrAgS7gasZJd1pOoPbCTdGxcHh-G4A9Tlf5zCnGJmqtshMt72edmcXdIapaZNPp4VJp5Ar9PHZbUrbwDsPjTSUrnOI=3D@protonmail.com>
     [not found]                                                                                                                             ` <59LofhYhxl7MLEuElXwZcESRB6MpjdG-iq-89B63siDRo5k0j-y6z-PVa6Y3iE1xE5LkJwpwTFi82bd0RZjB1yZbSJptFdPTBWfvOGj1W78=3D@protonmail.com>
2023-12-05  4:35                                                                                                                           ` waffl3x
2023-12-05  4:39                                                                                                                             ` waffl3x
2023-12-05  5:54                                                                                                                               ` waffl3x
2023-12-06  7:33                                                                                                                                 ` [PATCH v7 " waffl3x
2023-12-06  8:48                                                                                                                                   ` Jakub Jelinek
2023-12-06  9:31                                                                                                                                     ` waffl3x
2023-12-06 11:08                                                                                                                                   ` waffl3x
2023-12-08 19:25                                                                                                                                   ` Jason Merrill
2023-12-10 15:22                                                                                                                                     ` waffl3x
2023-12-10 18:59                                                                                                                                       ` Jason Merrill
2023-12-22  9:01                                                                                                                                         ` waffl3x
2023-12-22 17:26                                                                                                                                           ` Jason Merrill
2023-12-23  7:10                                                                                                                                             ` waffl3x
2023-12-26 16:37                                                                                                                                               ` Jason Merrill
2024-01-01 15:17                                                                                                                                                 ` waffl3x
2024-01-01 15:34                                                                                                                                                   ` waffl3x
2024-01-01 17:12                                                                                                                                                     ` waffl3x
2024-01-06 12:37                                                                                                                                                       ` waffl3x
2023-11-25 17:32                                                                                               ` [PATCH v5 " Jason Merrill
2023-11-25 22:59                                                                                                 ` waffl3x
2023-09-19 20:24   ` [PATCH 1/2] " Jason Merrill
     [not found] <b=5FiIXwWwO63ZE1ZSZHUIAdWyA2sqGsE3FM7eXfsInWogDyBZRsw8CwNsvFSDmEVmBtdq0pqb4zJ55HN2JCR7boDNramlEfne-R5PWdUXjbA=3D@protonmail.com>

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='z_Np7zbsi7jPllaaPNZ3g-UPoIRGVfvJ-7WzujG1awUL4Gp8iw8PI4fTrf962fafb4GU2ikJ7C88SLWot9iO9n-iemoSSQwFFdf5v4pO7FA=@protonmail.com' \
    --to=waffl3x@protonmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@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).