Document number: |
00-0028/N1251 |
Date: |
September 5, 2000 |
Author: |
John Spicer, Edison Design Group |
|
jhs@edg.com |
Definition of Dependent Name
Introduction
This document contains the proposed working paper changes for
the definition of dependent name.
(See core issue #224.) This issue was previously discussed
in N1231.
At the Tokyo meeting, the core group agreed on the direction proposed
in N1231, that the "dependency" of a name should be based on its type,
and not on the form of reference used, and that special rules are needed
to get the desired behavior when referring to names declared within the
class template itself.
Proposed Changes
Replace section 14.6.2.1 (temp.dep.type) with the following:
In the definition of a class template or a member of a class template,
a name refers to the current instantiation if it is
-
The injected-class-name of the class template.
-
The name of the class template followed by its
template-parameters enclosed in <>.
A template-argument whose value is the
template-parameter may be substituted for a particular
template-parameter when determining whether a given name refers
to the current instantiation.
template class A {
A* p1; // A is the current instantation
A* p2; // A is the current instantiation
typedef T TT;
A* p3; // A is the current instantiation
A p4; // A is not the current instantiation
};
A name is a member of the current instantiation if it is
-
An unqualified name that, when looked up, refers to a member of a class
template.
-
A qualified-id in which the nested-name-specifier
refers to the current instantiation.
[Example:
template class A {
static const int i = 5;
int n1[i]; // i refers to a member of the current instantiation
int n2[A::i]; // A::i refers to a member of the current instantiation
int n3[A::i]; // A::i refers to a member of the current instantiation
int f();
};
template int A::f()
{
return i; // i refers to a member of the current instantiation
}
--end example]
A name is a member of an unknown specialization if the name
is a qualified-id in which the nested-name-specifier
names a dependent type that is not the current instantiation.
A type is dependent if it is
-
a template parameter,
-
a member of an unknown specialization,
-
a cv-qualified type where the cv-unqualified type is dependent,
-
a compound type constructed from any dependent type,
-
an array type constructed from any dependent type or whose size is
specified by a constant expression that is value-dependent,
-
a template-id in which either the template name is a template
parameter or any of the template arguments is a dependent type or an
expression that is type-dependent or value-dependent.
Note: Because typedefs do not introduce new types, but instead simply refer
to other types, a name that refers to a typedef that is a member of the
current instantiation is dependent only if the type referred to is dependent.
In 14.6.2.2:
Replace
-
a nested-name-specifier that contains a class-name that
names a dependent type.
with
- a nested-name-specifier or qualified-id that names
a member of an unknown specialization
Add the following paragraph:
A class member access expression ([expr.ref]) is type-dependent
if the type of the referenced member is dependent.
Note: In an expression of the form x.y
or
xp->y
the type of the expression is usually the type of
the member y
of class of x
(or the class
pointed to by xp
). However, if x
or
xp
refers to a dependent type that is not the current
instantiation, the type of y
is always dependent. If
x
or xp
refers to a non-dependent type or
refers to the current instantiation, the type of y
is the
type of the class member access expression.
End of document.