public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101356] New: The non-public member of a local class cannot be accessed by a friend of the class
@ 2021-07-07  2:39 xmh970252187 at gmail dot com
  2021-08-02 15:35 ` [Bug c++/101356] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: xmh970252187 at gmail dot com @ 2021-07-07  2:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101356
           Summary: The non-public member of a local class cannot be
                    accessed by a friend of the class
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xmh970252187 at gmail dot com
  Target Milestone: ---

````
auto fun(){
    void show();
    struct C{
        friend void show();
        private:
          int c;
    };
    return C{};
}
void show(){
   auto o = fun();
   o.c = 0;
}
````
Clang accepts this example while GCC rejects it by reporting an error
diagnosis. 

As per [class.friend#1]

> A friend of a class is a function or class that is given permission to name the >private and protected members of the class. A class specifies its friends, if >any, by way of friend declarations. Such declarations give special access rights >to the friends, but they do not make the nominated friends members of the >befriending class.

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

* [Bug c++/101356] The non-public member of a local class cannot be accessed by a friend of the class
  2021-07-07  2:39 [Bug c++/101356] New: The non-public member of a local class cannot be accessed by a friend of the class xmh970252187 at gmail dot com
@ 2021-08-02 15:35 ` pinskia at gcc dot gnu.org
  2021-12-13 15:58 ` pinskia at gcc dot gnu.org
  2023-08-23 18:14 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-02 15:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-02
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=20357
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

Most likely related to PR 20357 too.

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

* [Bug c++/101356] The non-public member of a local class cannot be accessed by a friend of the class
  2021-07-07  2:39 [Bug c++/101356] New: The non-public member of a local class cannot be accessed by a friend of the class xmh970252187 at gmail dot com
  2021-08-02 15:35 ` [Bug c++/101356] " pinskia at gcc dot gnu.org
@ 2021-12-13 15:58 ` pinskia at gcc dot gnu.org
  2023-08-23 18:14 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-13 15:58 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2021-08-02 00:00:00         |2021-12-13
             Blocks|                            |65608

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
When we do friend void ::show(); we get the following warning:

<source>: In function 'auto fun()':
<source>:5:21: warning: 'void show()' has not been declared within '::'
    5 |         friend void ::show();
      |                     ^~
<source>:3:10: note: only here as a 'friend'
    3 |     void show();
      |          ^~~~


And even this is rejected:
namespace A {
void show();
}
auto fun(){
    struct C{
        friend void A::show();
        private:
          int c;
    };
    return C{};
}
void A::show(){
   auto o = fun();
   o.c = 0;
}


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65608
[Bug 65608] [meta-bug] friend issues

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

* [Bug c++/101356] The non-public member of a local class cannot be accessed by a friend of the class
  2021-07-07  2:39 [Bug c++/101356] New: The non-public member of a local class cannot be accessed by a friend of the class xmh970252187 at gmail dot com
  2021-08-02 15:35 ` [Bug c++/101356] " pinskia at gcc dot gnu.org
  2021-12-13 15:58 ` pinskia at gcc dot gnu.org
@ 2023-08-23 18:14 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-23 18:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> And even this is rejected:

This was fixed in GCC 10.5.0, 11.4.0, 12.3.0 and 13+. But the original example
is still broken.

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

end of thread, other threads:[~2023-08-23 18:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-07  2:39 [Bug c++/101356] New: The non-public member of a local class cannot be accessed by a friend of the class xmh970252187 at gmail dot com
2021-08-02 15:35 ` [Bug c++/101356] " pinskia at gcc dot gnu.org
2021-12-13 15:58 ` pinskia at gcc dot gnu.org
2023-08-23 18:14 ` pinskia 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).