This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


375. Confusing example on lookup with typename

Section: 13.8  [temp.res]     Status: dup     Submitter: Manish Pagey     Date: 23 August 2002

Section 13.8 [temp.res] paragraph 4 uses the following example to show that qualified name lookup described in Section 6.5.5 [basic.lookup.qual] applies even in the presence of "typename":

  struct A {
    struct X { } ;
    int X ;
  } ;
  template<class T> void f(T t) {
    typename T::X x ; // ill-formed: finds the data member X
                      // not the member type X
  }

This example is confusing because the definition of the template function itself is not ill formed unless it is instantiated with "A" as the template parameter. In other words, the example should be modified to something like:

  struct A {
    struct X { } ;
    int X ;
  } ;
  struct B {
    struct X { } ;
  } ;
  template<class T> void f(T t) {
    typename T::X x ;
  }
  void foo() {
    A a ;
    B b ;
    f(b) ; // OK -- finds member type B::X.
    f(a) ; // ill-formed: finds the data member A::X not
           // the member type A::X.
  }

Notes from October 2002 meeting:

This is a duplicate of Core Issue 345.