C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: The issue about the wording "member of a class"
From: Andrew Schepler (aschepler_at_[hidden])
Date: 2020-09-15 18:14:23


>
> In order to does not violate the rule "In the definition of a class or
> class template, the scope of a dependent base class is not examined during
> unqualified name lookup either at the point of definition of the class
> template or member or during an instantiation of the class template or
> member. "
>

The class `C` should be considered as a member of the enclosing template
> class `A`.

I disagree. Calling a member of a nested class of class X also a member of
X would change the meaning of far too many other rules about members,
beyond the "friend" example you noticed.

On "direct member": A member of class X which is not a direct member of X
is a direct member of some base class of X. Roughly speaking, members with
names are the names which are valid for the class member lookup used by
X::M and X_expr.M ([class.qual]
<https://timsong-cpp.github.io/cppwp/class.qual>).

Instead, I think possibly all four points in [temp.dep.type]/1 are missing
phrasing to say that the rules for "the current instantiation" apply in a
member of a nested class, and recursively if the enclosing class is itself
a nested class. The Standard seems inconsistent on whether "nested class"
must mean a member, or can be a member of a member, etc. I see multiple
uses of the term which only make sense for actual members, and multiple
uses of the term which only make sense including recursive members. Maybe
defining "direct nested class", "indirect nested class", and "nested class"
(and similar for "enclosing class") would be helpful?

-- Andrew Schepler

On Tue, Sep 15, 2020 at 4:00 AM jim x via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> Hi, everyone.
>
> Please consider the following code
> ````
>
> template<class T> struct A {
> typedef int M;
> struct B {
> typedef void M;
> struct C;
> };};
> template<class T> struct A<T>::B::C : A<T> {
> M m; // OK, A<T>::M};
>
> ````
>
> It is an example written in [temp.dep.type]
> <https://timsong-cpp.github.io/cppwp/n4659/temp.dep.type>. whether the
> name `A<T>` is a current-instantiation name is determined by the following
> rules:
> >A name refers to the *current instantiation*
> <https://timsong-cpp.github.io/cppwp/n4659/temp.dep.type#def:current_instantiation> if
> it is
> >> in the definition of a primary class template or *a member of a
> primary class template*, the name of the class template followed by the
> template argument list of the primary template (as described below)
> enclosed in <> (or an equivalent template alias specialization),
>
> I have to say that the class `C` is a *direct member* of the class `B`
> which in turn is the direct member of the class template `A`, however I
> have not find any rule in the standard says that such a member of a nested
> class is also be considered as a member of enclosing classes. I only find
> the definition of the wording "direct member", that is:
>
> >A direct member of a class X is a member of X that was first declared
> within the member-specification of X, including anonymous union objects
> ([class.union.anon]) and direct members thereof.
>
> In order to does not violate the rule "In the definition of a class or
> class template, the scope of a dependent base class is not examined during
> unqualified name lookup either at the point of definition of the class
> template or member or during an instantiation of the class template or
> member. "
>
> The class `C` should be considered as a member of the enclosing template
> class `A`.
>

> If this speculation is true, then there will be another question, that is
> `friend`, the rule says:
> >A friend of a class is a function or class that is given permission to
> use the private and protected member names from the class.
>
> But, obviously, any function or class that befriended does not have
> permission to access the private members of a nested class of which the
> befriending class is an enclosing class.
>
> So, my questions are:
>
> Issue A:
> Could members of a nested class be viewed as members of enclosing
> classes?
>
> Issues B:
> If the answers to A is "yes", should the rule for `friend` be changed to:
> >A friend of a class is a function or class that is given permission to
> use the private and protected *direct member names *from the class.
>
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups