This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Bug report: Access scope
- To: Philippe Bouchard <philippeb at corel dot com>
- Subject: Re: Bug report: Access scope
- From: Martin Sebor <sebor at roguewave dot com>
- Date: Sun, 29 Oct 2000 14:44:15 -0700
- CC: gcc-bugs <gcc-bugs at gcc dot gnu dot org>
- Organization: Rogue Wave Software, Inc.
- References: <39F85BDA.D98AAE59@corel.com>
Philippe Bouchard wrote:
>
> The following program:
> #include <iostream>
>
> struct A
> {
> void function() { cout << __PRETTY_FUNCTION__ << endl; }
> };
>
> struct B : public A
> {
> void function() { cout << __PRETTY_FUNCTION__ << endl; }
> };
>
> struct C : protected B
> {
> A::function;
> };
>
> int main(...)
> {
> C c;
> c.function();
> }
>
> Reports:
> scopechange.cpp: In function `int main(...)':
> scopechange.cpp:10: `void B::function()' is inaccessible
> scopechange.cpp:21: within this context
Besides the obvious problems in the testcase (missing std::
qualification and the incorrect prototype of main()), the compiler is
actually correct in rejecting the code, albeit for the wrong reason.
From 7.3.3, p14:
...The base class members mentioned by a using-declaration shall be
visible in the scope of at least one of the direct base classes of the
class where the using-declaration is specified...
A::f is not visible in the scope of B (it's hidden by B::function). The
error message issued by g++ is as if the access-declaration did not
exist and so is confusing.
However, the real bug shows up when you change the inheritance from
protected to public. The compiler then accepts the code but ends up
calling B::f which is incorrect and certainly not what is intended.
Regards
Martin
>
> Under:
> Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.2/specs
> gcc version 2.95.2 20000220 (Debian GNU/Linux)
>
> Thank you.