Topic: Access demotion in using-declarations


Author: "Robert B. Murray" <rmurray@team6.com>
Date: 1998/05/22
Raw View
What happens if I attempt to demote the access of a member with
a using-declaration?
---------------
struct B {
 int m;
};
struct N : public B {
private:
 using B::m;
};

int main(){
 N n;
 n.m; // Legal?
}
---------------
I know that this is a Bad Thing from a design point of view; but what
should the compiler do about it?  I can find no language in the Standard
banning it.

Here's my best guess: even if the name is introduced as "private"
in the scope of N, the access checking rules of 11.2-4
(class.access.base) will thwart the attempt to hide B::m.  The fourth
subitem of that paragraph is:

"A member m is accessible when named in class N if ... there exists a
base class B of N that is accessible at the point of reference, and m is
accessible when named in class B."

B is an accessible base class and m is accessible when named in class B,
so the above code compiles despite the using-declaration.

Is this right? If so, shouldn't the compiler issue at least a warning,
if not an error, on an attempt to demote access in this way?

Rob Murray
Sarajen Software


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]