1
votes

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:

  1. Declarations that are visible at the point of definition of the template.
  2. 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.

1
Comments are not for extended discussion; this conversation has been moved to chat.Samuel Liew

1 Answers

0
votes

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,

  • the type T is indeed a dependent type
  • the expression typename T::type is a qualified name and the left if :: is a dependent type
  • that expression becomes an unknown specialization

Then 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.