[Bug c++/19377] New: Using declaration in "private" part causes "protected" diagnostic
redi at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Tue Jan 11 16:25:00 GMT 2005
Given this code:
class A {
protected:
int i;
};
class B : public A {
private:
using A::i;
};
class C : public B {
public:
void f() { A::i = 0; }
};
g++ 3.4 and 4.0 say:
protinherit.cc: In member function 'void C::f()':
protinherit.cc:5: error: 'int A::i' is protected
protinherit.cc:15: error: within this context
(It actually prints the message twice, but that's PR 19375)
The diagnostic says A::i is protected, but surely if it was protected it would
be accessible in C, since C is derived from A ?
Also, the using declaration is in the private section of B, so again, it can't
be protected, can it?
Should the diagnostic actually say "A::i is private in this context" or "A::i is
inaccessible in this context" ?
Even if that's the right diagnostic for this behaviour, is the behaviour right?
Does that using directive change the access of i ?
It makes sense to me that if C refers to the member as A::i it should have
access. Accessing B::i might fail, but A::i should be OK ... shouldn't it?
I can't see anything in the standard that says whether using decls can be used
to _reduce_ access, the closest is at the end of [namespace.udecl] which says:
The alias created by the using-declaration has the usual accessibility
for a member-declaration.
That would imply B::i is private. I'm not sure what "alias" means in that
context but it implies to me that A::i is still public.
Every version of GCC I have since 2.95 behaves the same and rejects the code,
but como says it is OK. I've not added the rejects-valid keyword as I'm not sure
it should be there.
FWIW, if the access of i in A is changed from protected to public, the
diagnostic says A::i is "inaccessible" not "protected". So that diagnostic is
right, given GCC's behaviour - but there's still the question of whether the
behaviour's right.
--
Summary: Using declaration in "private" part causes "protected"
diagnostic
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: redi at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19377
More information about the Gcc-bugs
mailing list