C++ Logo

std-discussion

Advanced search

Re: using and weird member access

From: Yongwei Wu <wuyongwei_at_[hidden]>
Date: Tue, 12 May 2026 19:48:38 +0800
Actually, if we change

struct Derived : public Middle { public: using ::Base::member; };

to

struct Derived : public Middle { public: using Base::member; };

Clang will reject the code. So it seems to me that Clang is applying
different rules to the type identification and the using declaration. But
[namespace.udecl]/3 <https://eel.is/c++draft/namespace.udecl#3> says each
using-declarator shall either name an enumerator or have a
nested-name-specifier naming a base class of the current class.

So now I think Clang is simply confused and this is a bug.

On Tue, 12 May 2026 at 01:44, Anoop Rana via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> Looks like namespace.udecl#14 <https://eel.is/c++draft/namespace.udecl#14> makes
> this ill-formed.
>
> On Mon, 11 May 2026 at 23:04, Brian Bi via Std-Discussion <
> std-discussion_at_[hidden]> wrote:
>
>> 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?
>>>
>>

Received on 2026-05-12 11:48:56