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

2023-01-15


1770. Type matching of non-type template parameters and arguments

Section: 13.10.3.6  [temp.deduct.type]     Status: C++14     Submitter: Canada     Date: 2013-09-24

N3690 comment CA 15

[Moved to DR at the February, 2014 meeting.]

According to 13.10.3.6 [temp.deduct.type] paragraph 17,

If, in the declaration of a function template with a non-type template-parameter, the non-type template-parameter is used in an expression in the function parameter-list and, if the corresponding template-argument is deduced, the template-argument type shall match the type of the template-parameter exactly, except that a template-argument deduced from an array bound may be of any integral type.

This does not cover return types, leaving the outcome of an example like the following unclear:

  template <int N> struct A;

  template <short N>
  A<N> *foo();

  void bar() {
    A<1> *(*fp)(void) = &foo;
  }

Proposed resolution (September, 2013):

Change 13.10.3.6 [temp.deduct.type] paragraph 17 as follows:

If, in the declaration of a function template with a non-type template-parameter, the non-type template-parameter is used in an expression in the function parameter-list and, if the corresponding template-argument is deduced, the template-argument type shall match the type of the template-parameter exactly, except that a template-argument deduced from an array bound may be of any integral type P has a form that contains <i>, and if the type of the corresponding value of A differs from the type of i, deduction fails. If P has a form that contains [i], and if the type of i is not an integral type, deduction fails.147 [Example:...