Title
Default template arguments for template members of non-template classes
Status
review
Section
13.2 [temp.param]
Submitter
Mike Miller

Created on 2022-08-22.00:00:00 last changed 18 months ago

Messages

Date: 2023-06-20.19:34:52

Proposed resolution:

Change in 13.2 [temp.param] paragraph 10 as follows:

... A default template-argument may be specified in a template declaration. A default template-argument shall not be specified in the template-parameter-lists of the definition of a member of a class template templated class C that appears outside of the member's class class-specifier of C. A default template-argument shall not be specified in a friend class template declaration. If a friend function template declaration D specifies a default template-argument, that declaration shall be a definition and there shall be no other declaration of the function template which is reachable from D or from which D is reachable.
Date: 2022-08-22.00:00:00

Consider:

struct S {
  template<typename> void f();
};

template<typename = int> void S::f() { }   // ok?

There is implementation divergence in the treatment of this example. The relevant wording appears to be 13.2 [temp.param] paragraph 12:

A default template-argument shall not be specified in the template-parameter-lists of the definition of a member of a class template that appears outside of the member's class.

However, the example above deals with a member of an ordinary class, not a class template, but it is not clear why there should be a difference between a member template of a class template and a member template of a non-template class.

Alternatively, it is not clear why the example above should be treated differently from a non-member function template, e.g.,

template<typename> void f();
template<typename = int> void f() { }

which is explicitly permitted.

History
Date User Action Args
2023-06-20 19:34:52adminsetmessages: + msg7336
2023-06-20 19:34:52adminsetstatus: open -> review
2022-08-22 00:00:00admincreate