public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Bug: C++ access checking
@ 1999-04-30 23:15 Nathan Sidwell
1999-04-30 23:15 ` Mark Mitchell
0 siblings, 1 reply; 2+ messages in thread
From: Nathan Sidwell @ 1999-04-30 23:15 UTC (permalink / raw)
To: egcs-bugs
Hi,
I believe this to be a bug, but it's possibly my misunderstanding of 11.2/4.
struct A
{
protected:
int m;
};
struct C : A
{
void foo(A *);
void baz(C *);
};
void C::foo(A *ptr)
{
ptr->m;
}
void C::baz(C *ptr)
{
ptr->m;
}
the 19990405 snapshot says,
nathan@manao:161>ss-g++ -c access.C
access.C: In method `void C::foo(A *)':
access.C:4: `int A::m' is protected
access.C:15: within this context
I think A::m is accessible in C::foo, even though we're not accessing this's
A::m, but some random A *'s. The third case given in 11.2/4 says,
"m as a member of N if protected, and the reference occurs ... in a member of
friend of a class P derived from N, where m as a member of P is private or
protected."
In this case N is A, and P is C. m is protected in C and we're in a member of
C. It doesn't mention that the object we're fetching m from has to be a P.
Or am I missing something?
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Bug: C++ access checking
1999-04-30 23:15 Bug: C++ access checking Nathan Sidwell
@ 1999-04-30 23:15 ` Mark Mitchell
0 siblings, 0 replies; 2+ messages in thread
From: Mark Mitchell @ 1999-04-30 23:15 UTC (permalink / raw)
To: nathan; +Cc: egcs-bugs
>>>>> "Nathan" == Nathan Sidwell <nathan@acm.org> writes:
Nathan> In this case N is A, and P is C. m is protected in C and
Nathan> we're in a member of C. It doesn't mention that the object
Nathan> we're fetching m from has to be a P.
Nathan> Or am I missing something?
[class.protected]
When a friend or a member function of a derived class references a
protected nonstatic member of a base class, an access check applies in
addition to those described earlier in clause _class.access_.4) Except
when forming a pointer to member (_expr.unary.op_), the access must be
through a pointer to, reference to, or object of the derived class
itself (or any class derived from that class) (_expr.ref_). If the
access is to form a pointer to member, the nested-name-specifier shall
name the derived class (or any class derived from that class).
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-04-30 23:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-30 23:15 Bug: C++ access checking Nathan Sidwell
1999-04-30 23:15 ` Mark Mitchell
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).