Template default arguments and deduction failure
17.9.2 [temp.deduct]
John Spicer

Created on 2012-10-31.00:00:00 last changed 62 months ago


Date: 2015-05-15.00:00:00

Notes from the May, 2015 meeting:

CWG agreed that a default template argument should only be used if the parameter is not used in a deducible context. See also issue 2092.

Date: 2015-04-13.00:00:00

Additional note, April, 2015:

EWG has requested that CWG resolve this issue along the lines discussed above.

Date: 2013-11-15.00:00:00

Rationale (November, 2013):

CWG felt that this issue should be considered by EWG in a broader context before being resolved.

Date: 2012-10-31.00:00:00

According to 17.9.2 [temp.deduct] paragraph 5,

The resulting substituted and adjusted function type is used as the type of the function template for template argument deduction. If a template argument has not been deduced and its corresponding template parameter has a default argument, the template argument is determined by substituting the template arguments determined for preceding template parameters into the default argument. If the substitution results in an invalid type, as described above, type deduction fails.

This leaves the impression that default arguments are used after deduction failure leaves an argument undeduced. For example,

  template<typename T> struct Wrapper;
  template<typename T = int> void f(Wrapper<T>*);
  void g() {

Deduction fails for T, so presumably int is used. However, some implementations reject this code. It appears that the intent would be better expressed as something like

...If a template argument is used only in a non-deduced context and its corresponding template parameter has a default argument...
Date User Action Args
2015-05-25 00:00:00adminsetmessages: + msg5532
2015-05-25 00:00:00adminsetstatus: open -> drafting
2015-04-13 00:00:00adminsetmessages: + msg5321
2015-04-13 00:00:00adminsetstatus: extension -> open
2014-01-20 00:00:00adminsetmessages: + msg4796
2014-01-20 00:00:00adminsetstatus: drafting -> extension
2013-05-03 00:00:00adminsetstatus: open -> drafting
2012-10-31 00:00:00admincreate