From Jason Turner

[class.copy.elision]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpac_if3nh/{from.md → to.md} +40 -37
tmp/tmpac_if3nh/{from.md → to.md} RENAMED
@@ -1,57 +1,60 @@
1
  ### Copy/move elision <a id="class.copy.elision">[[class.copy.elision]]</a>
2
 
3
  When certain criteria are met, an implementation is allowed to omit the
4
- copy/move construction of a class object, even if the constructor
5
- selected for the copy/move operation and/or the destructor for the
6
- object have side effects. In such cases, the implementation treats the
7
- source and target of the omitted copy/move operation as simply two
8
- different ways of referring to the same object. If the first parameter
9
- of the selected constructor is an rvalue reference to the object’s type,
10
- the destruction of that object occurs when the target would have been
11
- destroyed; otherwise, the destruction occurs at the later of the times
12
- when the two objects would have been destroyed without the
13
- optimization.[^14]
14
 
15
- This elision of copy/move operations, called *copy elision*, is
16
- permitted in the following circumstances (which may be combined to
17
- eliminate multiple copies):
18
 
19
- - in a `return` statement in a function with a class return type, when
20
- the *expression* is the name of a non-volatile object with automatic
21
- storage duration (other than a function parameter or a variable
22
- introduced by the *exception-declaration* of a *handler*
23
- [[except.handle]]) with the same type (ignoring cv-qualification) as
24
- the function return type, the copy/move operation can be omitted by
25
- constructing the object directly into the function call’s return
26
- object
 
 
 
27
  - in a *throw-expression* [[expr.throw]], when the operand is the name
28
- of a non-volatile object with automatic storage duration (other than a
29
- function or catch-clause parameter) that belongs to a scope that does
30
- not contain the innermost enclosing *compound-statement* associated
31
- with a *try-block* (if there is one), the copy/move operation can be
32
- omitted by constructing the object directly into the exception object
 
 
33
  - in a coroutine [[dcl.fct.def.coroutine]], a copy of a coroutine
34
  parameter can be omitted and references to that copy replaced with
35
  references to the corresponding parameter if the meaning of the
36
  program will be unchanged except for the execution of a constructor
37
- and destructor for the parameter copy object
38
- - when the *exception-declaration* of an exception handler
39
- [[except.pre]] declares an object of the same type (except for
40
- cv-qualification) as the exception object [[except.throw]], the copy
41
- operation can be omitted by treating the *exception-declaration* as an
42
- alias for the exception object if the meaning of the program will be
43
- unchanged except for the execution of constructors and destructors for
44
- the object declared by the *exception-declaration*. \[*Note 1*: There
45
- cannot be a move from the exception object because it is always an
46
- lvalue. — *end note*]
47
 
48
  Copy elision is not permitted where an expression is evaluated in a
49
  context requiring a constant expression [[expr.const]] and in constant
50
  initialization [[basic.start.static]].
51
 
52
- [*Note 2*: It is possible that copy elision is performed if the same
53
  expression is evaluated in another context. — *end note*]
54
 
55
  [*Example 1*:
56
 
57
  ``` cpp
 
1
  ### Copy/move elision <a id="class.copy.elision">[[class.copy.elision]]</a>
2
 
3
  When certain criteria are met, an implementation is allowed to omit the
4
+ creation of a class object from a source object of the same type
5
+ (ignoring cv-qualification), even if the selected constructor and/or the
6
+ destructor for the object have side effects. In such cases, the
7
+ implementation treats the source and target of the omitted
8
+ initialization as simply two different ways of referring to the same
9
+ object. If the first parameter of the selected constructor is an rvalue
10
+ reference to the object’s type, the destruction of that object occurs
11
+ when the target would have been destroyed; otherwise, the destruction
12
+ occurs at the later of the times when the two objects would have been
13
+ destroyed without the optimization.
14
 
15
+ [*Note 1*: Because only one object is destroyed instead of two, and the
16
+ creation of one object is omitted, there is still one object destroyed
17
+ for each one constructed. — *end note*]
18
 
19
+ This elision of object creation, called *copy elision*, is permitted in
20
+ the following circumstances (which may be combined to eliminate multiple
21
+ copies):
22
+
23
+ - in a `return` statement [[stmt.return]] in a function with a class
24
+ return type, when the *expression* is the name of a non-volatile
25
+ object o with automatic storage duration (other than a function
26
+ parameter or a variable introduced by the *exception-declaration* of a
27
+ *handler* [[except.handle]]), the copy-initialization of the result
28
+ object can be omitted by constructing o directly into the function
29
+ call’s result object;
30
  - in a *throw-expression* [[expr.throw]], when the operand is the name
31
+ of a non-volatile object o with automatic storage duration (other than
32
+ a function parameter or a variable introduced by the
33
+ *exception-declaration* of a *handler*) that belongs to a scope that
34
+ does not contain the innermost enclosing *compound-statement*
35
+ associated with a *try-block* (if there is one), the
36
+ copy-initialization of the exception object can be omitted by
37
+ constructing o directly into the exception object;
38
  - in a coroutine [[dcl.fct.def.coroutine]], a copy of a coroutine
39
  parameter can be omitted and references to that copy replaced with
40
  references to the corresponding parameter if the meaning of the
41
  program will be unchanged except for the execution of a constructor
42
+ and destructor for the parameter copy object;
43
+ - when the *exception-declaration* of a *handler* [[except.handle]]
44
+ declares an object o, the copy-initialization of o can be omitted by
45
+ treating the *exception-declaration* as an alias for the exception
46
+ object if the meaning of the program will be unchanged except for the
47
+ execution of constructors and destructors for the object declared by
48
+ the *exception-declaration*. \[*Note 2*: There cannot be a move from
49
+ the exception object because it is always an lvalue. *end note*]
 
 
50
 
51
  Copy elision is not permitted where an expression is evaluated in a
52
  context requiring a constant expression [[expr.const]] and in constant
53
  initialization [[basic.start.static]].
54
 
55
+ [*Note 3*: It is possible that copy elision is performed if the same
56
  expression is evaluated in another context. — *end note*]
57
 
58
  [*Example 1*:
59
 
60
  ``` cpp