Title
Invalid return types and template argument deduction
Status
cd1
Section
13.10.3 [temp.deduct]
Submitter
John Spicer

Created on 2004-11-16.00:00:00 last changed 196 months ago

Messages

Date: 2006-04-15.00:00:00

[Voted into WP at April, 2006 meeting.]

Date: 2005-10-15.00:00:00

Proposed resolution (October, 2005):

Change the last sub-bullet of 13.10.3 [temp.deduct] paragraph 2 as indicated:

  • Attempting to create a function type in which a parameter has a type of void, or in which the return type is a function type or array type.

Date: 2004-11-16.00:00:00

According to 13.10.3 [temp.deduct] paragraph 2,

If a substitution in a template parameter or in the function type of the function template results in an invalid type, type deduction fails.

That would seem to apply to cases like the following:

    template <class T> T f(T&){}
    void f(const int*){}
    int main() {
      int a[5];
      f(a);
    }

Here, the return type of f is deduced as int[5], which is invalid according to 9.3.4.6 [dcl.fct] paragraph 6. The outcome of this example, then, should presumably be that type deduction fails and overload resolution selects the non-template function. However, the list of reasons in 13.10.3 [temp.deduct] for which type deduction can fail does not include function and array types as a function return type. Those cases should be added to the list.

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2006-11-05 00:00:00adminsetstatus: dr -> wp
2006-04-22 00:00:00adminsetmessages: + msg1371
2006-04-22 00:00:00adminsetstatus: ready -> dr
2005-10-22 00:00:00adminsetmessages: + msg1225
2005-10-22 00:00:00adminsetstatus: drafting -> ready
2005-05-01 00:00:00adminsetstatus: open -> drafting
2004-11-16 00:00:00admincreate