Title
Declaration matching in explicit instantiations
Status
drafting
Section
13.9.3 [temp.explicit]
Submitter
Richard Smith

Created on 2013-04-19.00:00:00 last changed 124 months ago

Messages

Date: 2014-01-20.00:00:00

Additional note, January, 2014:

A related example has been raised:

  template<typename T> class Matrix {
  public:
    Matrix(){}
    Matrix(const Matrix&){}
    template<typename U>
      Matrix(const Matrix<U>&);
  };

  template Matrix<int>::Matrix(const Matrix&);

  Matrix<int> m;
  Matrix<int> mm(m);

If the explicit instantiation directive applies to the constructor template, there is no way to explicitly instantiate the copy constructor.

Date: 2013-04-19.00:00:00

Consider a case like

  struct X {
    template<typename T> void f(T);
    void f(int);
  };
  template void X::f(int);

or

  template<typename T> void f(T) {}
  void f(int);
  template void f(int);

Presumably in both these cases the explicit instantiation should refer to the template and not to the non-template; however, 13.7.3 [temp.mem] paragraph 2 says,

A normal (non-template) member function with a given name and type and a member function template of the same name, which could be used to generate a specialization of the same type, can both be declared in a class. When both exist, a use of that name and type refers to the non-template member unless an explicit template argument list is supplied.

This would appear to give the wrong answer for the first example. It's not clearly stated, but consistency would suggest a similar wrong answer for the second. Presumably a statement is needed somewhere that an explicit instantiation directive applies to a template and not a non-template function if both are visible.

History
Date User Action Args
2014-01-20 00:00:00adminsetmessages: + msg4747
2013-10-14 00:00:00adminsetstatus: open -> drafting
2013-04-19 00:00:00admincreate