Title
Confusing relationship between templates and copy constructors
Status
c++11
Section
11.4.5.3 [class.copy.ctor]
Submitter
Jason Merrill

Created on 2010-06-19.00:00:00 last changed 123 months ago

Messages

Date: 2011-03-15.00:00:00

[Voted into the WP at the March, 2011 meeting.]

Date: 2010-11-15.00:00:00

Proposed resolution (November, 2010):

Merge 11.4.5.3 [class.copy.ctor] paragraphs 6 and 7 and change the text as follows:

A declaration of a constructor for a class X is ill-formed if its first parameter is of type (optionally cv-qualified) X and either there are no other parameters or else all other parameters have default arguments. A member function template is never instantiated to perform the copy of a class object to an object of its class type produce such a constructor signature. [Example:

  struct S {
    template<typename T> S(T);
    template<typename T> S(T&&);
    S();
  };

  S f();
  const S g;

  void h() {
    S a( f() ); // does not instantiate member template;
                // uses the implicitly generated move constructor
    S a(g);     // does not instantiate the member template to produce S::S<S>(S);
                // uses the implicitly generated declared copy constructor
}
Date: 2022-02-18.07:47:23

11.4.5.3 [class.copy.ctor] paragraphs 6-7 currently read,

A declaration of a constructor for a class X is ill-formed if its first parameter is of type (optionally cv-qualified) X and either there are no other parameters or else all other parameters have default arguments.

A member function template is never instantiated to perform the copy of a class object to an object of its class type. [Example:

    struct S {
        template<typename T> S(T);
        template<typename T> S(T&&);
        S();
    };

    S f();
    const S g;

    void h() {
        S a( f() ); // does not instantiate member template;
                    // uses the implicitly generated move constructor
        S a(g);     // does not instantiate the member template;
                    // uses the implicitly generated copy constructor
    }

These paragraphs were previously a single paragraph, and the second sentence was intended to mean that

    template <class T> A(T):

will never be instantiated to produce A(A). It should not have been split and the example should not have been amended to include move construction.

Lawrence Crowl: I suggest something along the lines of

A member function template is never instantiated to match the signature of an ill-formed constructor.
History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3369
2011-04-10 00:00:00adminsetstatus: ready -> fdis
2010-11-29 00:00:00adminsetmessages: + msg3060
2010-11-29 00:00:00adminsetstatus: drafting -> ready
2010-06-19 00:00:00admincreate