1

cppreference.com cites two cases for the Mandatory elision of copy/move operations. I'm interested in the second case as follows:

In the initialization of an object, when the initializer expression is a prvalue of the same class type (ignoring cv-qualification) as the variable type.

Thus, the initialization below will have mandatory elision of the copy operation:

T x = T();

In fact, this initialization doesn't compile in C++14 when T's copy constructor is deleted, but it does compile in C++17 (see example), as stated in cppreference.com.

But I can't find a quote in [class.copy.elision] supporting this.

Alexander
  • 2,581
  • 11
  • 17

1 Answers1

2

That's because the wording is in [dcl.init]/17.6.1

  • Otherwise, if the destination type is a (possibly cv-qualified) class type:

    • If the initializer expression is a prvalue and the cv-unqualified version of the source type is the same class as the class of the destination, the initializer expression is used to initialize the destination object. [ Example: T x = T(T(T())); calls the T default constructor to initialize x. — end example ]

Guaranteed copy elision involved a clever alteration of the way value categories behave and interact. So it's spread across several places in the standard. You can see them by examining the original proposal

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458