tmp/tmpe25rrekg/{from.md → to.md}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
## Constructors and destructors <a id="except.ctor">[[except.ctor]]</a>
|
| 2 |
|
| 3 |
As control passes from the point where an exception is thrown to a
|
| 4 |
-
handler,
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
constructed, but not yet destroyed, since the try block was entered. If
|
| 9 |
an exception is thrown during the destruction of temporaries or local
|
| 10 |
-
variables for a `return` statement
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
[*Example 1*:
|
| 15 |
|
| 16 |
``` cpp
|
| 17 |
struct A { };
|
|
@@ -29,34 +29,41 @@ A f() {
|
|
| 29 |
return {}; // #2
|
| 30 |
}
|
| 31 |
```
|
| 32 |
|
| 33 |
At \#1, the returned object of type `A` is constructed. Then, the local
|
| 34 |
-
variable `b` is destroyed
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
— *end example*]
|
| 40 |
|
| 41 |
If the initialization or destruction of an object other than by
|
| 42 |
delegating constructor is terminated by an exception, the destructor is
|
| 43 |
invoked for each of the object’s direct subobjects and, for a complete
|
| 44 |
object, virtual base class subobjects, whose initialization has
|
| 45 |
-
completed
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
If the *compound-statement* of the *function-body* of a delegating
|
| 53 |
constructor for an object exits via an exception, the object’s
|
| 54 |
destructor is invoked. Such destruction is sequenced before entering a
|
| 55 |
handler of the *function-try-block* of a delegating constructor for that
|
| 56 |
object, if any.
|
| 57 |
|
| 58 |
-
[*Note
|
| 59 |
-
[[expr.new]]
|
| 60 |
-
[[basic.stc.dynamic.deallocation]]
|
| 61 |
storage occupied by the object. — *end note*]
|
| 62 |
|
|
|
|
| 1 |
## Constructors and destructors <a id="except.ctor">[[except.ctor]]</a>
|
| 2 |
|
| 3 |
As control passes from the point where an exception is thrown to a
|
| 4 |
+
handler, objects with automatic storage duration are destroyed by a
|
| 5 |
+
process, specified in this subclause, called *stack unwinding*.
|
| 6 |
|
| 7 |
+
Each object with automatic storage duration is destroyed if it has been
|
| 8 |
constructed, but not yet destroyed, since the try block was entered. If
|
| 9 |
an exception is thrown during the destruction of temporaries or local
|
| 10 |
+
variables for a `return` statement [[stmt.return]], the destructor for
|
| 11 |
+
the returned object (if any) is also invoked. The objects are destroyed
|
| 12 |
+
in the reverse order of the completion of their construction.
|
| 13 |
|
| 14 |
[*Example 1*:
|
| 15 |
|
| 16 |
``` cpp
|
| 17 |
struct A { };
|
|
|
|
| 29 |
return {}; // #2
|
| 30 |
}
|
| 31 |
```
|
| 32 |
|
| 33 |
At \#1, the returned object of type `A` is constructed. Then, the local
|
| 34 |
+
variable `b` is destroyed [[stmt.jump]]. Next, the local variable `y` is
|
| 35 |
+
destroyed, causing stack unwinding, resulting in the destruction of the
|
| 36 |
+
returned object, followed by the destruction of the local variable `a`.
|
| 37 |
+
Finally, the returned object is constructed again at \#2.
|
| 38 |
|
| 39 |
— *end example*]
|
| 40 |
|
| 41 |
If the initialization or destruction of an object other than by
|
| 42 |
delegating constructor is terminated by an exception, the destructor is
|
| 43 |
invoked for each of the object’s direct subobjects and, for a complete
|
| 44 |
object, virtual base class subobjects, whose initialization has
|
| 45 |
+
completed [[dcl.init]] and whose destructor has not yet begun execution,
|
| 46 |
+
except that in the case of destruction, the variant members of a
|
| 47 |
+
union-like class are not destroyed.
|
| 48 |
+
|
| 49 |
+
[*Note 1*: If such an object has a reference member that extends the
|
| 50 |
+
lifetime of a temporary object, this ends the lifetime of the reference
|
| 51 |
+
member, so the lifetime of the temporary object is effectively not
|
| 52 |
+
extended. — *end note*]
|
| 53 |
+
|
| 54 |
+
The subobjects are destroyed in the reverse order of the completion of
|
| 55 |
+
their construction. Such destruction is sequenced before entering a
|
| 56 |
+
handler of the *function-try-block* of the constructor or destructor, if
|
| 57 |
+
any.
|
| 58 |
|
| 59 |
If the *compound-statement* of the *function-body* of a delegating
|
| 60 |
constructor for an object exits via an exception, the object’s
|
| 61 |
destructor is invoked. Such destruction is sequenced before entering a
|
| 62 |
handler of the *function-try-block* of a delegating constructor for that
|
| 63 |
object, if any.
|
| 64 |
|
| 65 |
+
[*Note 2*: If the object was allocated by a *new-expression*
|
| 66 |
+
[[expr.new]], the matching deallocation function
|
| 67 |
+
[[basic.stc.dynamic.deallocation]], if any, is called to free the
|
| 68 |
storage occupied by the object. — *end note*]
|
| 69 |
|