C++ Logo

std-discussion

Advanced search

The issue about the wording "member of a class"

From: jim x <xmh970252187_at_[hidden]>
Date: Tue, 15 Sep 2020 15:59:27 +0800
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.

Received on 2020-09-15 02:59:42