This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


2311. Missed case for guaranteed copy elision

Section:  [over.match.list]     Status: open     Submitter: Richard Smith     Date: 2016-08-09


  struct 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], [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.