[C++ bug] another type access control problem
Nathan Sidwell
nathan@acm.org
Thu Feb 10 06:58:00 GMT 2000
Jason,
here's another problem. The attached program says,
nathan@manao:335>./g++ -B ./ -ansi -pedantic nathan96.C -c
nathan96.C: In method `void Derived::Other::Foo ()':
nathan96.C:12: `class Base::Nested' is protected
nathan96.C:31: within this context
a) I don't think Base::Nested is protected withing Derived::Other.
Derived::Other is a friend of Derived, Base is public in Derived and
Base::Nested is public in Base.
b) Whether or not Base::Nested is accessible, what has that to
do with Core's accessibility?
NB The typedefs & friendship in Derived::Nested are important in
triggering the fault. If friendship is declared without using the
typedef'd type Owner, no diagnostic is reported. Neither is a diagnostic
reported if the typedef Parent removed.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
Never hand someone a gun unless you are sure where they will point it
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
// Build don't link:
// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 10 Feb 2000 <nathan@acm.org>
// A nested class should be able to use the type of a public base
struct Core {};
struct Base : Core
{
protected:
class Nested
{ // gets bogus error - XFAIL *-*-*
};
};
struct Derived : Base
{
protected:
struct Nested : public Base::Nested
{
public:
typedef Derived Owner;
typedef Base::Nested Parent;
friend class Owner;
};
struct Other
{
void Foo ()
{
Core *ptr; // gets bogus error - XFAIL *-*-*
}
};
};
More information about the Gcc-bugs
mailing list