public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52136] New: g++ is wrongly propagating "friend class" to the parent class
@ 2012-02-06 13:14 sylvestre at debian dot org
  2012-02-06 13:40 ` [Bug c++/52136] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: sylvestre at debian dot org @ 2012-02-06 13:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52136

             Bug #: 52136
           Summary: g++ is wrongly propagating "friend class" to the
                    parent class
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sylvestre@debian.org


---
class address 
{
protected:
    static int parseNext(int a);
};


class mailbox : public address
{
    friend class mailboxField;
};

class mailboxField
{
    void parse(int a)
        {
            address::parseNext(a);
            // will work with:
            // mailbox::parseNext(a);
        }
};
---

It should trigger:
address.cpp: In member function ‘void mailboxField::parse(int)’:
address.cpp:4:16: error: ‘static int address::parseNext(int)’ is protected
address.cpp:17:33: error: within this context

Tested with g++ 4.6.2


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

* [Bug c++/52136] g++ is wrongly propagating "friend class" to the parent class
  2012-02-06 13:14 [Bug c++/52136] New: g++ is wrongly propagating "friend class" to the parent class sylvestre at debian dot org
@ 2012-02-06 13:40 ` redi at gcc dot gnu.org
  2012-02-06 13:50 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-06 13:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52136

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-06 13:40:08 UTC ---
EDG and Solaris CC also accept it, clang doesn't

The code looks similar to this example from [class.protected] in the standard:

class B {
protected:
    int i;
    static int j;
};
class D1 : public B {
};
class D2 : public B {
    friend void fr(B*,D1*,D2*);
};
void fr(B* pb, D1* p1, D2* p2) {
    // ...
    p2->i = 3;    // OK (access through a D2)
    p2->B::i = 4; // OK (access through a D2, even though
                  // naming class is B)
    // ...
    B::j = 5;     // OK (because refers to static member)
    D2::j = 6;    // OK (because refers to static member)
}

Note that the friend of D2 can access non-static members of B through D2* and
can access static members of B directly.


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

* [Bug c++/52136] g++ is wrongly propagating "friend class" to the parent class
  2012-02-06 13:14 [Bug c++/52136] New: g++ is wrongly propagating "friend class" to the parent class sylvestre at debian dot org
  2012-02-06 13:40 ` [Bug c++/52136] " redi at gcc dot gnu.org
@ 2012-02-06 13:50 ` redi at gcc dot gnu.org
  2012-02-06 13:58 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-06 13:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52136

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-06 13:50:40 UTC ---
I think G++ is correct here.

[class.protected]p1
An additional access check beyond those described earlier in Clause 11 is
applied when a non-static data member or non-static member function is a
protected member of its naming class (11.2)*

* This additional check does not apply to other members, e.g., static data
members or enumerator member constants.


address::parseNext refers to the same entity as mailbox::parseNext and access
to static members does not involve an object expression, so there is no need
for that access to be done through an object expression of the derived type.


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

* [Bug c++/52136] g++ is wrongly propagating "friend class" to the parent class
  2012-02-06 13:14 [Bug c++/52136] New: g++ is wrongly propagating "friend class" to the parent class sylvestre at debian dot org
  2012-02-06 13:40 ` [Bug c++/52136] " redi at gcc dot gnu.org
  2012-02-06 13:50 ` redi at gcc dot gnu.org
@ 2012-02-06 13:58 ` redi at gcc dot gnu.org
  2012-02-06 14:09 ` sylvestre at debian dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-06 13:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52136

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-06 13:56:58 UTC ---
Clang gets this wrong on purpose: http://llvm.org/bugs/show_bug.cgi?id=6840

But G++ implements what the standard says, so INVALID


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

* [Bug c++/52136] g++ is wrongly propagating "friend class" to the parent class
  2012-02-06 13:14 [Bug c++/52136] New: g++ is wrongly propagating "friend class" to the parent class sylvestre at debian dot org
                   ` (2 preceding siblings ...)
  2012-02-06 13:58 ` redi at gcc dot gnu.org
@ 2012-02-06 14:09 ` sylvestre at debian dot org
  2012-02-06 14:25 ` redi at gcc dot gnu.org
  2014-02-16 13:17 ` jackie.rosen at hushmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: sylvestre at debian dot org @ 2012-02-06 14:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52136

--- Comment #4 from Sylvestre Ledru <sylvestre at debian dot org> 2012-02-06 14:08:21 UTC ---
I found this bug (or behavior) while playing with clang. 

I am not really sure to understand why friend class should impact his parent
but if g++ respects the standard, why not...


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

* [Bug c++/52136] g++ is wrongly propagating "friend class" to the parent class
  2012-02-06 13:14 [Bug c++/52136] New: g++ is wrongly propagating "friend class" to the parent class sylvestre at debian dot org
                   ` (3 preceding siblings ...)
  2012-02-06 14:09 ` sylvestre at debian dot org
@ 2012-02-06 14:25 ` redi at gcc dot gnu.org
  2014-02-16 13:17 ` jackie.rosen at hushmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-06 14:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52136

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-06 14:24:39 UTC ---
(In reply to comment #4)
> I am not really sure to understand why friend class should impact his parent
> but if g++ respects the standard, why not...

It doesn't "impact his parent"

Read comment 2 again.  To access a protected non-static member you must do so
though an object expression of the derived type, because in the expression
'p->address::m' you only know if 'm' is a member of a 'mailbox' object when 'p'
has type 'mailbox*'

But for a static member that is irrelevant, the static member just exists
independently of any 'mailbox' or 'address' instance, so if mailboxField can
access members of 'mailbox' then it can access the static member, and it
doesn't matter if you refer to it as 'mailbox::parseNext' or
'address::parseNext' because both refer to the exact same entity.


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

* [Bug c++/52136] g++ is wrongly propagating "friend class" to the parent class
  2012-02-06 13:14 [Bug c++/52136] New: g++ is wrongly propagating "friend class" to the parent class sylvestre at debian dot org
                   ` (4 preceding siblings ...)
  2012-02-06 14:25 ` redi at gcc dot gnu.org
@ 2014-02-16 13:17 ` jackie.rosen at hushmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: jackie.rosen at hushmail dot com @ 2014-02-16 13:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52136

Jackie Rosen <jackie.rosen at hushmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jackie.rosen at hushmail dot com

--- Comment #6 from Jackie Rosen <jackie.rosen at hushmail dot com> ---
*** Bug 260998 has been marked as a duplicate of this bug. ***
Seen from the domain http://volichat.com
Page where seen: http://volichat.com/adult-chat-rooms
Marked for reference. Resolved as fixed @bugzilla.


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

end of thread, other threads:[~2014-02-16 13:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-06 13:14 [Bug c++/52136] New: g++ is wrongly propagating "friend class" to the parent class sylvestre at debian dot org
2012-02-06 13:40 ` [Bug c++/52136] " redi at gcc dot gnu.org
2012-02-06 13:50 ` redi at gcc dot gnu.org
2012-02-06 13:58 ` redi at gcc dot gnu.org
2012-02-06 14:09 ` sylvestre at debian dot org
2012-02-06 14:25 ` redi at gcc dot gnu.org
2014-02-16 13:17 ` jackie.rosen at hushmail dot com

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