This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug report: Access scope


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]