Title
Is a constrained member function a template?
Status
concepts
Section
11.4 [class.mem]
Submitter
Daniel Krügler

Created on 2009-03-20.00:00:00 last changed 187 months ago

Messages

Date: 2022-02-18.07:47:23

According to 11.4 [class.mem] paragraph 19,

A non-template member-declaration that has a member-requirement (_N2914_.14.11.1 [temp.req]) is a constrained member and shall occur only in a class template (13.7.2 [temp.class]) or nested class thereof. The member-declaration for a constrained member shall declare a member function. A constrained member is treated as a constrained template (_N2914_.14.11 [temp.constrained]) whose template requirements include the requirements specified in its member-requirement clause and the requirements of each enclosing constrained template.

Furthermore, 13.7.3 [temp.mem] paragraph 9 says,

A member template of a constrained class template is itself a constrained template (_N2914_.14.11 [temp.constrained])...

and illustrates this statement with the following example:

    concept C<typename T> { void f(const T&); }
    concept D<typename T> { void g(const T&); }

    template<C T> class A {
      requires D<T> void h(const T& x) {
        f(x); // OK: C<T>::f
        g(x); // OK: D<T>::g
      }
    };

If these passages are taken at face value and a constrained member function is, in fact, “treated as a... template,” there are negative consequences. For example, according to 11.4.5.3 [class.copy.ctor] paragraph 2, a member function template is never considered to be a copy constructor, so a constrained constructor that is in the form of a copy constructor does not suppress the implicit declaration and definition of a default copy constructor. Also, according to 13.7.3 [temp.mem] paragraph 3, a member function template cannot be virtual, so it is not possible to specify a member-requirement clause for a virtual function.

Presumably these consequences are unintended, so the wording that suggests otherwise should be revised to make that clear.

History
Date User Action Args
2009-08-03 00:00:00adminsetstatus: open -> concepts
2009-03-20 00:00:00admincreate