Title
Missed case for guaranteed copy elision
Status
open
Section
12.2.2.8 [over.match.list]
Submitter
Richard Smith

Created on 2016-08-09.00:00:00 last changed 101 months ago

Messages

Date: 2022-09-15.21:52:22

Consider:

  struct X {
    X();
  };
  X make();
  X x{make()}; 

We reach 9.4.5 [dcl.init.list] bullet 3.7:

Otherwise, if T is a class type, constructors are considered. The applicable constructors are enumerated and the best one is chosen through overload resolution (12.2 [over.match], 12.2.2.8 [over.match.list]).

This means we perform a redundant copy. If T were an aggregate, 9.4.5 [dcl.init.list] bullet 3.2 would avoid the redundant copy:

If T is an aggregate class and the initializer list has a single element of type cv U, where U is T or a class derived from T, the object is initialized from that element (by copy-initialization for copy-list-initialization, or by direct-initialization for direct-list-initialization).

See also issues 2137 and 2327.

History
Date User Action Args
2016-08-09 00:00:00admincreate