About how lookup the dependent name for template, The standard only gives a little sentence like this, there's no more:
In resolving dependent names, names from the following sources are considered:
- Declarations that are visible at the point of definition of the template.
- Declarations from namespaces associated with the types of the function arguments both from the instantiation context ([temp.point]) and from the definition context.
Consider the below code
struct Test{
using type = int;
};
// #1
template<typename T>
struct TMP{
using type = typename T::type;
};
int main(){
TMP<Test>::type v = 0;
}
For this code, the name type
indeed a dependent name because T is a template parameter and here is not a function call, So, the only relevant bullet point is Number 1. It only says the dependent name shall be visible before the template definition, It means in my code, the declaration shall be visible at #1
. In actually, typename T::type
is a qualified-id, hence qualified name lookup rules apply to it and because T
is a template parameter, So the lookup action shall be occurred after given a template argument, namely, during the instantiation of a specialization for such a template. But the quote I cited does not say anything about this. So, I wonder Is it a defect in the standard? If I miss anything that interpret this in the standard, please cite them for this question.
To complete language-lawyer comments, in §"Unknown specializations" of this page
Within a template definition, certain names are deduced to belong to an unknown specialization, in particular,
- a qualified name, if any name that appears to the left of :: is a dependent type that is not a member of the current instantiation
- ...
In your struct TMP
,
T
is indeed a dependent typetypename T::type
is a qualified name and the left if ::
is a dependent typeThen it is said:
Members of unknown specialization are always dependent, and are looked up and bound at the point of instantiation as all dependent names
which allows the lookup of TMP<Test>::type
at the point of instanciation.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments