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


621. Template argument deduction from function return types

Section: 13.9.4  [temp.expl.spec]     Status: C++11     Submitter: Richard Corden     Date: 16 February 2007

[Voted into WP at August, 2010 meeting.]

It does not appear that the following example is well-formed, although most compilers accept it:

    template <typename T> T foo();
    template <> int foo();

The reason is that 13.9.4 [temp.expl.spec] paragraph 11 only allows trailing template-arguments to be omitted if they “can be deduced from the function argument type,” and there are no function arguments in this example.

13.9.4 [temp.expl.spec] should probably say “function type” instead of “function argument type.” Also, a subsection should probably be added to 13.10.3 [temp.deduct] to cover “Deducing template arguments from declarative contexts” or some such. It would be essentially the same as 13.10.3.3 [temp.deduct.funcaddr] except that the function type from the declaration would be used as the type of P.

Proposed resolution (March, 2008):

  1. Insert the following as a new subsection after 13.10.3.6 [temp.deduct.type]:

  2. 14.9.2.6 Deducing template arguments in a declaration that names a specialization of a function template [temp.deduct.funcdecl]

    Template arguments can be deduced from the function type specified when declaring a specialization of a function template. [Note: this can occur in the context of an explicit specialization, an explicit instantiation, or a friend declaration. —end note] The function template's function type and the declared type are used as the types of P and A, and the deduction is done as described in 13.10.3.6 [temp.deduct.type].

  3. Change 13.9.4 [temp.expl.spec] paragraph 11 as follows:

  4. A trailing template-argument can be left unspecified in the template-id naming an explicit function template specialization provided it can be deduced from the function argument type (14.9.2.6 [temp.deduct.funcdecl])...

Notes from the September, 2008 meeting:

The proposed resolution is probably more than is needed. Instead of a complete new section, the material could become a paragraph in 13.7.7 [temp.fct].

Proposed resolution (February, 2010):

Add the following paragraph at the end of 13.7.7 [temp.fct]:

In a declaration that names a specialization of a function template, template arguments can be deduced from the function type. [Note: this can occur in the context of an explicit specialization, an explicit instantiation, or a friend declaration. —end note] The function template's function type and the declared type are used as the types of P and A and the deduction is done as described in 13.10.3.6 [temp.deduct.type].

Proposed resolution (March, 2010):

This issue is resolved by the resolution of issue 873.