Date: Mon, 11 May 2026 13:33:57 -0400
I think it's valid per the wording of the standard. Per
[class.access.base]/5 <https://eel.is/c++draft/class.access.base#5>, the
designating class is `Base`, and the member we are trying to access is
public when considered as a member of that designating class, therefore
access is granted.
It does seem to me like this shouldn't be valid, and I'm not sure if we
have the wording to make it so. Since [namespace.udecl]/3
<https://eel.is/c++draft/namespace.udecl#3> says that you must name a base
class, it seems to me that there is some missing wording saying that it
must be an accessible base class.
That's because we treat *using-declarations* (with the only exception being
when they name constructors) as if they declared a name in a new scope that
happens to refer to the same entity as that name in the original scope. So
if we say that `using ::Base::member;` is valid, then we cannot stop
`Derived` from being able to use `member` without further qualification,
since it would then be accessing its *own* member, not that of a base
class. This doesn't seem like the right result, so the only option is to
make the *using-declaration* illegal.
On Mon, May 11, 2026 at 11:31 AM Yongwei Wu via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> Is the following code valid?
>
> class Base { public: int member; };
> class Middle : private Base {};
> struct Derived : public Middle { public: using ::Base::member; };
>
> I am inclined to think it is not valid, as :Base::member is not really
> accessible inside Derived. I believe accessibility is a requirement:
> https://eel.is/c++draft/namespace.udecl#14.sentence-1.
>
> However, while GCC rejects the code, both Clang and EDG accept it:
> https://godbolt.org/z/Y33drKb6n.
>
> Any comments?
>
> --
> Yongwei Wu
> URL: http://wyw.dcweb.cn/
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
[class.access.base]/5 <https://eel.is/c++draft/class.access.base#5>, the
designating class is `Base`, and the member we are trying to access is
public when considered as a member of that designating class, therefore
access is granted.
It does seem to me like this shouldn't be valid, and I'm not sure if we
have the wording to make it so. Since [namespace.udecl]/3
<https://eel.is/c++draft/namespace.udecl#3> says that you must name a base
class, it seems to me that there is some missing wording saying that it
must be an accessible base class.
That's because we treat *using-declarations* (with the only exception being
when they name constructors) as if they declared a name in a new scope that
happens to refer to the same entity as that name in the original scope. So
if we say that `using ::Base::member;` is valid, then we cannot stop
`Derived` from being able to use `member` without further qualification,
since it would then be accessing its *own* member, not that of a base
class. This doesn't seem like the right result, so the only option is to
make the *using-declaration* illegal.
On Mon, May 11, 2026 at 11:31 AM Yongwei Wu via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> Is the following code valid?
>
> class Base { public: int member; };
> class Middle : private Base {};
> struct Derived : public Middle { public: using ::Base::member; };
>
> I am inclined to think it is not valid, as :Base::member is not really
> accessible inside Derived. I believe accessibility is a requirement:
> https://eel.is/c++draft/namespace.udecl#14.sentence-1.
>
> However, while GCC rejects the code, both Clang and EDG accept it:
> https://godbolt.org/z/Y33drKb6n.
>
> Any comments?
>
> --
> Yongwei Wu
> URL: http://wyw.dcweb.cn/
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
-- *Brian Bi*
Received on 2026-05-11 17:34:16
