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

2024-05-06


422. Is a typedef redeclaration allowed with a template type that might be the same?

Section: 9.2.4  [dcl.typedef]     Status: NAD     Submitter: Steve Adamczyk     Date: 18 June 2003

Is the following valid?

  template <class T> void f(T) {
    typedef int x;
    typedef T x;
  }
  int main() {
    f(1);
  }

There is an instantiation where the function is valid. Is an implementation allowed to issue an error on the template declaration because the types on the typedef are not the same (9.2.4 [dcl.typedef])?

How about

  typedef T x;
  typedef T2 x;
?

It can be argued that these cases should be allowed because they aren't necessarily wrong, but it can also be argued that there's no reason to write things like the first case above, and if such a case appears it's more likely to be a mistake than some kind of intentional test that int and T are the same type.

Notes from the October 2003 meeting:

We believe that all these cases should be allowed, and that errors should be required only when an instance of the template is generated. The current standard wording does not seem to disallow such cases, so no change is required.