public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106756] New: Overbroad friendship for nested classes
@ 2022-08-26 15:16 herring at lanl dot gov
  2022-08-26 15:19 ` [Bug c++/106756] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: herring at lanl dot gov @ 2022-08-26 15:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106756

            Bug ID: 106756
           Summary: Overbroad friendship for nested classes
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: herring at lanl dot gov
  Target Milestone: ---

Sometime since 12.2, GCC has started accepting

struct A {
  struct B {
    friend int f(B*) {return i;}
  };
private:
  static int i;
};

despite the express limitation in [class.nest]/4 (/3 in the latest draft). 
(Current Clang also accepts it, but ICC and MSVC do not.)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/106756] Overbroad friendship for nested classes
  2022-08-26 15:16 [Bug c++/106756] New: Overbroad friendship for nested classes herring at lanl dot gov
@ 2022-08-26 15:19 ` redi at gcc dot gnu.org
  2022-08-26 15:34 ` herring at lanl dot gov
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-08-26 15:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106756

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
           Keywords|                            |accepts-invalid

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Started to be accepted with Jason's r13-465:

    c++: hidden friend access [DR1699]

    It has come up several times that Clang considers hidden friends of a class
    to be sufficiently memberly to be covered by a friend declaration naming
the
    class.  This is somewhat unclear in the standard: [class.friend] says
    "Declaring a class to be a friend implies that private and protected
members
    of the class granting friendship can be named in the base-specifiers and
    member declarations of the befriended class."

    A hidden friend is a syntactic member-declaration, but is it a "member
    declaration"?  CWG was ambivalent, and referred the question to EWG as a
    design choice.  But recently Patrick mentioned that the current G++ choice
    not to treat it as a "member declaration" was making his library work
    significantly more cumbersome, so let's go ahead and vote the other way.

    This means that the testcases for 100502 and 58993 are now accepted.

            DR1699
            PR c++/100502
            PR c++/58993

    gcc/cp/ChangeLog:

            * friend.cc (is_friend): Hidden friends count as members.
            * search.cc (friend_accessible_p): Likewise.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/106756] Overbroad friendship for nested classes
  2022-08-26 15:16 [Bug c++/106756] New: Overbroad friendship for nested classes herring at lanl dot gov
  2022-08-26 15:19 ` [Bug c++/106756] " redi at gcc dot gnu.org
@ 2022-08-26 15:34 ` herring at lanl dot gov
  2022-08-29  8:25 ` [Bug c++/106756] [13 Regression] " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: herring at lanl dot gov @ 2022-08-26 15:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106756

--- Comment #2 from S. Davis Herring <herring at lanl dot gov> ---
(In reply to Jonathan Wakely from comment #1)
>     "Declaring a class to be a friend implies that private and protected members
>     of the class granting friendship can be named in the base-specifiers and
>     member declarations of the befriended class."
>     
>     A hidden friend is a syntactic member-declaration, but is it a "member
>     declaration"?

That argument doesn't quite apply here: B is the class granting friendship, but
it's A's member being accessed.  To allow this, we'd have to say that B's
friendship gives f access to everything to which B has access, but that would
just be transitive friendship, which is known to be wrong.

That said, one can make a similar argument along the lines of "B is a
member-declaration of A, and so f is part of a member-declaration itself",
which puts us back on the old question of whether it matters whether the friend
is defined inside the class.  Indeed, GCC still rejects the example modified to
use

int f(A::B*) {return A::i;}

but that's an even stronger contradiction with [class.nest]/4 (which uses
"defined within a nested class").

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/106756] [13 Regression] Overbroad friendship for nested classes
  2022-08-26 15:16 [Bug c++/106756] New: Overbroad friendship for nested classes herring at lanl dot gov
  2022-08-26 15:19 ` [Bug c++/106756] " redi at gcc dot gnu.org
  2022-08-26 15:34 ` herring at lanl dot gov
@ 2022-08-29  8:25 ` rguenth at gcc dot gnu.org
  2022-09-12 19:27 ` [Bug c++/106756] [CWG1699] " jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-08-29  8:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106756

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
            Summary|Overbroad friendship for    |[13 Regression] Overbroad
                   |nested classes              |friendship for nested
                   |                            |classes

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/106756] [CWG1699] Overbroad friendship for nested classes
  2022-08-26 15:16 [Bug c++/106756] New: Overbroad friendship for nested classes herring at lanl dot gov
                   ` (2 preceding siblings ...)
  2022-08-29  8:25 ` [Bug c++/106756] [13 Regression] " rguenth at gcc dot gnu.org
@ 2022-09-12 19:27 ` jason at gcc dot gnu.org
  2023-04-26  6:56 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2022-09-12 19:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106756

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[13 Regression] Overbroad   |[CWG1699] Overbroad
                   |friendship for nested       |friendship for nested
                   |classes                     |classes
   Last reconfirmed|                            |2022-09-12
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |SUSPENDED

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to S. Davis Herring from comment #2)
> That said, one can make a similar argument along the lines of "B is a
> member-declaration of A, and so f is part of a member-declaration itself",

Exactly.

> which puts us back on the old question of whether it matters whether the
> friend is defined inside the class.  Indeed, GCC still rejects the example
> modified to use
> 
> int f(A::B*) {return A::i;}

Yes, because there the definition of f is not (part of) a member-declaration.

Friends defined in the class body are different in various ways from normal
functions that happen to be friends; it makes sense to me for this to be one
such.

Suspending pending the resolution of CWG1699.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/106756] [CWG1699] Overbroad friendship for nested classes
  2022-08-26 15:16 [Bug c++/106756] New: Overbroad friendship for nested classes herring at lanl dot gov
                   ` (3 preceding siblings ...)
  2022-09-12 19:27 ` [Bug c++/106756] [CWG1699] " jason at gcc dot gnu.org
@ 2023-04-26  6:56 ` rguenth at gcc dot gnu.org
  2023-05-30 12:33 ` ppalka at gcc dot gnu.org
  2023-07-27  9:23 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-26  6:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106756

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|13.0                        |13.2

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.1 is being released, retargeting bugs to GCC 13.2.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/106756] [CWG1699] Overbroad friendship for nested classes
  2022-08-26 15:16 [Bug c++/106756] New: Overbroad friendship for nested classes herring at lanl dot gov
                   ` (4 preceding siblings ...)
  2023-04-26  6:56 ` rguenth at gcc dot gnu.org
@ 2023-05-30 12:33 ` ppalka at gcc dot gnu.org
  2023-07-27  9:23 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-30 12:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106756

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jlame646 at gmail dot com

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 110037 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/106756] [CWG1699] Overbroad friendship for nested classes
  2022-08-26 15:16 [Bug c++/106756] New: Overbroad friendship for nested classes herring at lanl dot gov
                   ` (5 preceding siblings ...)
  2023-05-30 12:33 ` ppalka at gcc dot gnu.org
@ 2023-07-27  9:23 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27  9:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106756

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|13.2                        |13.3

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-27  9:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26 15:16 [Bug c++/106756] New: Overbroad friendship for nested classes herring at lanl dot gov
2022-08-26 15:19 ` [Bug c++/106756] " redi at gcc dot gnu.org
2022-08-26 15:34 ` herring at lanl dot gov
2022-08-29  8:25 ` [Bug c++/106756] [13 Regression] " rguenth at gcc dot gnu.org
2022-09-12 19:27 ` [Bug c++/106756] [CWG1699] " jason at gcc dot gnu.org
2023-04-26  6:56 ` rguenth at gcc dot gnu.org
2023-05-30 12:33 ` ppalka at gcc dot gnu.org
2023-07-27  9:23 ` rguenth at gcc dot gnu.org

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).