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

2024-04-05


345. Misleading comment on example in templates chapter

Section: 13.8  [temp.res]     Status: CD1     Submitter: Jason Shirk     Date: 18 March 2002

[Voted into WP at April 2003 meeting.]

The following example from 13.8 [temp.res] paragraph 4:

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
}

is not ill-formed. The intent of the example is obvious, but some mention should be made that it is only ill-formed when T=A. For other T's, it could be well formed.

Proposed resolution (October 2002):

In 13.8 [temp.res] paragraph 4, replace the example with:

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 -- T::X refers to B::X.
  f(a);  // error: T::X refers to the data member A::X not
         // the struct A::X.
}