public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/19377] New: Using declaration in "private" part causes "protected" diagnostic
Date: Tue, 11 Jan 2005 16:25:00 -0000	[thread overview]
Message-ID: <20050111161422.19377.redi@gcc.gnu.org> (raw)

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


             reply	other threads:[~2005-01-11 16:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-11 16:25 redi at gcc dot gnu dot org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050111161422.19377.redi@gcc.gnu.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).