Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-12-20


1080. Confusing relationship between templates and copy constructors

Section:11.4.5.3  [class.copy.ctor]    Status:C++11    Submitter:Jason Merrill    Date:2010-06-19

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

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

A declaration of a constructor for a classX is ill-formedif its first parameter is of type (optionally cv-qualified)Xand either there are no other parameters or else all other parametershave default arguments.

A member function template is never instantiated to perform thecopy of a class object to an object of its classtype. [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 secondsentence was intended to mean that

    template <class T> A(T):

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

Lawrence Crowl: I suggest something along the lines of

A member function template is never instantiated to match thesignature of an ill-formed constructor.

Proposed resolution (November, 2010):

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

A declaration of a constructor for a classX is ill-formedif its first parameter is of type (optionally cv-qualified)Xand either there are no other parameters or else all other parametershave default arguments. A member function template is neverinstantiated toperform the copy of a class object to an objectof its class typeproduce such a constructorsignature. [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 templateto produceS::S<S>(S);                // uses the implicitlygenerateddeclared copy constructor}



[8]ページ先頭

©2009-2026 Movatter.jp