public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19377] New: Using declaration in "private" part causes "protected" diagnostic
@ 2005-01-11 16:25 redi at gcc dot gnu dot org
  2005-01-11 17:08 ` [Bug c++/19377] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: redi at gcc dot gnu dot org @ 2005-01-11 16:25 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 17+ messages in thread
[parent not found: <bug-19377-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2021-04-28 18:48 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-11 16:25 [Bug c++/19377] New: Using declaration in "private" part causes "protected" diagnostic redi at gcc dot gnu dot org
2005-01-11 17:08 ` [Bug c++/19377] " pinskia at gcc dot gnu dot org
2005-01-12 10:46 ` lerdsuwa at gcc dot gnu dot org
2005-05-01  3:34 ` pinskia at gcc dot gnu dot org
     [not found] <bug-19377-4@http.gcc.gnu.org/bugzilla/>
2010-11-12 15:08 ` fabien at gcc dot gnu.org
2011-11-27 21:44 ` fabien at gcc dot gnu.org
2012-04-15 17:11 ` manu at gcc dot gnu.org
2012-04-15 17:18 ` pinskia at gcc dot gnu.org
2012-04-15 17:42 ` manu at gcc dot gnu.org
2012-04-15 18:24 ` fabien at gcc dot gnu.org
2014-02-06 14:22 ` abel at gcc dot gnu.org
2014-02-06 16:20 ` fabien at gcc dot gnu.org
2014-02-07  5:12 ` abel at gcc dot gnu.org
2014-02-08  8:44 ` harald at gigawatt dot nl
2014-02-08 15:57 ` redi at gcc dot gnu.org
2021-01-29 12:22 ` anthonysharp15 at gmail dot com
2021-04-28 18:48 ` anthonysharp15 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).