Title
Return type deduction for address of function
Status
c++14
Section
9.2.9.6 [dcl.spec.auto]
Submitter
Richard Smith

Created on 2013-05-02.00:00:00 last changed 81 months ago

Messages

Date: 2013-11-15.00:00:00

Proposed resolution (November, 2013):

Add the following as a new paragraph at the end of 13.10.3.3 [temp.deduct.funcaddr]:

A placeholder type (9.2.9.6 [dcl.spec.auto]) in the return type of a function template is a non-deduced context. If template argument deduction succeeds for such a function, the return type is determined from instantiation of the function body.
Date: 2014-02-15.00:00:00

[Applied to WP at the February, 2014 meeting.]

The following example appears in 9.2.9.6 [dcl.spec.auto] paragraph 12:

  template <class T> auto f(T t) { return t; } // return type deduced at instantiation time
  typedef decltype(f(1)) fint_t;               // instantiates f<int> to deduce return type
  template<class T> auto f(T* t) { return *t; }
  void g() { int (*p)(int*) = &f; }            // instantiates both fs to determine return types,
                                               // chooses second

This is the desired behavior, but the current wording does not achieve that effect. One possible way this could work would be:

  • auto is treated as a non-deduced context

  • in 13.10.3.3 [temp.deduct.funcaddr], the deduced A is produced by substituting the deduced template arguments into the original function template, rather than substituting them into P, and the deduced A is the type of the produced function declaration (triggering instantiation of a definition as needed to complete the type)

History
Date User Action Args
2014-11-24 00:00:00adminsetstatus: accepted -> c++14
2014-03-03 00:00:00adminsetstatus: tentatively ready -> accepted
2014-01-20 00:00:00adminsetmessages: + msg4728
2014-01-20 00:00:00adminsetstatus: drafting -> tentatively ready
2013-10-14 00:00:00adminsetstatus: open -> drafting
2013-05-02 00:00:00admincreate