From Jason Turner

[support.exception]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpjzso1sb2/{from.md → to.md} +65 -43
tmp/tmpjzso1sb2/{from.md → to.md} RENAMED
@@ -17,45 +17,48 @@ namespace std {
17
  using terminate_handler = void (*)();
18
  terminate_handler get_terminate() noexcept;
19
  terminate_handler set_terminate(terminate_handler f) noexcept;
20
  [[noreturn]] void terminate() noexcept;
21
 
22
- int uncaught_exceptions() noexcept;
23
 
24
  using exception_ptr = unspecified;
25
 
26
- exception_ptr current_exception() noexcept;
27
- [[noreturn]] void rethrow_exception(exception_ptr p);
28
- template<class E> exception_ptr make_exception_ptr(E e) noexcept;
 
 
29
 
30
- template<class T> [[noreturn]] void throw_with_nested(T&& t);
31
- template<class E> void rethrow_if_nested(const E& e);
32
  }
33
  ```
34
 
35
  ### Class `exception` <a id="exception">[[exception]]</a>
36
 
37
  ``` cpp
38
  namespace std {
39
  class exception {
40
  public:
41
- exception() noexcept;
42
- exception(const exception&) noexcept;
43
- exception& operator=(const exception&) noexcept;
44
- virtual ~exception();
45
- virtual const char* what() const noexcept;
46
  };
47
  }
48
  ```
49
 
50
  The class `exception` defines the base class for the types of objects
51
  thrown as exceptions by C++ standard library components, and certain
52
  expressions, to report errors detected during program execution.
53
 
54
- Each standard library class `T` that derives from class `exception` has
55
- the following publicly accessible member functions, each of them having
56
- a non-throwing exception specification [[except.spec]]:
 
57
 
58
  - default constructor (unless the class synopsis shows other
59
  constructors)
60
  - copy constructor
61
  - copy assignment operator
@@ -65,28 +68,29 @@ postcondition: If two objects `lhs` and `rhs` both have dynamic type `T`
65
  and `lhs` is a copy of `rhs`, then `strcmp(lhs.what(), rhs.what())` is
66
  equal to `0`. The `what()` member function of each such `T` satisfies
67
  the constraints specified for `exception::what()` (see below).
68
 
69
  ``` cpp
70
- exception(const exception& rhs) noexcept;
71
- exception& operator=(const exception& rhs) noexcept;
72
  ```
73
 
74
  *Ensures:* If `*this` and `rhs` both have dynamic type `exception` then
75
  the value of the expression `strcmp(what(), rhs.what())` shall equal 0.
76
 
77
  ``` cpp
78
- virtual ~exception();
79
  ```
80
 
81
  *Effects:* Destroys an object of class `exception`.
82
 
83
  ``` cpp
84
- virtual const char* what() const noexcept;
85
  ```
86
 
87
- *Returns:* An *implementation-defined* NTBS.
 
88
 
89
  *Remarks:* The message may be a null-terminated multibyte
90
  string [[multibyte.strings]], suitable for conversion and display as a
91
  `wstring` [[string.classes]], [[locale.codecvt]]. The return value
92
  remains valid until the exception object from which it is obtained is
@@ -98,22 +102,22 @@ called.
98
  ``` cpp
99
  namespace std {
100
  class bad_exception : public exception {
101
  public:
102
  // see [exception] for the specification of the special member functions
103
- const char* what() const noexcept override;
104
  };
105
  }
106
  ```
107
 
108
  The class `bad_exception` defines the type of the object referenced by
109
  the `exception_ptr` returned from a call to `current_exception`
110
  [[propagation]] when the currently active exception object fails to
111
  copy.
112
 
113
  ``` cpp
114
- const char* what() const noexcept override;
115
  ```
116
 
117
  *Returns:* An *implementation-defined* NTBS.
118
 
119
  ### Abnormal termination <a id="exception.terminate">[[exception.terminate]]</a>
@@ -176,14 +180,15 @@ abandoned for any of several reasons [[except.terminate]]. May also be
176
  called directly by the program.
177
 
178
  ### `uncaught_exceptions` <a id="uncaught.exceptions">[[uncaught.exceptions]]</a>
179
 
180
  ``` cpp
181
- int uncaught_exceptions() noexcept;
182
  ```
183
 
184
- *Returns:* The number of uncaught exceptions [[except.uncaught]].
 
185
 
186
  *Remarks:* When `uncaught_exceptions() > 0`, throwing an exception can
187
  result in a call of the function `std::terminate` [[except.terminate]].
188
 
189
  ### Exception propagation <a id="propagation">[[propagation]]</a>
@@ -210,21 +215,23 @@ enumeration, or pointer type.
210
  as `exception_ptr`. — *end note*]
211
 
212
  For purposes of determining the presence of a data race, operations on
213
  `exception_ptr` objects shall access and modify only the `exception_ptr`
214
  objects themselves and not the exceptions they refer to. Use of
215
- `rethrow_exception` on `exception_ptr` objects that refer to the same
216
- exception object shall not introduce a data race.
217
 
218
  [*Note 2*: If `rethrow_exception` rethrows the same exception object
219
  (rather than a copy), concurrent access to that rethrown exception
220
  object can introduce a data race. Changes in the number of
221
  `exception_ptr` objects that refer to a particular exception do not
222
  introduce a data race. — *end note*]
223
 
 
 
224
  ``` cpp
225
- exception_ptr current_exception() noexcept;
226
  ```
227
 
228
  *Returns:* An `exception_ptr` object that refers to the currently
229
  handled exception [[except.handle]] or a copy of the currently handled
230
  exception, or a null `exception_ptr` object if no exception is being
@@ -242,15 +249,15 @@ If the attempt to copy the current exception object throws an exception,
242
  the function returns an `exception_ptr` object that refers to the thrown
243
  exception or, if this is not possible, to an instance of
244
  `bad_exception`.
245
 
246
  [*Note 4*: The copy constructor of the thrown exception can also fail,
247
- so the implementation is allowed to substitute a `bad_exception` object
248
- to avoid infinite recursion. — *end note*]
249
 
250
  ``` cpp
251
- [[noreturn]] void rethrow_exception(exception_ptr p);
252
  ```
253
 
254
  *Preconditions:* `p` is not a null pointer.
255
 
256
  *Effects:* Let u be the exception object to which `p` refers, or a copy
@@ -262,11 +269,11 @@ memory for the copy is allocated in an unspecified way.
262
  - otherwise, if copying the exception to which `p` refers to form u
263
  throws an exception, throws that exception;
264
  - otherwise, throws u.
265
 
266
  ``` cpp
267
- template<class E> exception_ptr make_exception_ptr(E e) noexcept;
268
  ```
269
 
270
  *Effects:* Creates an `exception_ptr` object that refers to a copy of
271
  `e`, as if:
272
 
@@ -279,28 +286,43 @@ try {
279
  ```
280
 
281
  [*Note 5*: This function is provided for convenience and efficiency
282
  reasons. — *end note*]
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  ### `nested_exception` <a id="except.nested">[[except.nested]]</a>
285
 
286
  ``` cpp
287
  namespace std {
288
  class nested_exception {
289
  public:
290
- nested_exception() noexcept;
291
- nested_exception(const nested_exception&) noexcept = default;
292
- nested_exception& operator=(const nested_exception&) noexcept = default;
293
- virtual ~nested_exception() = default;
294
 
295
  // access functions
296
- [[noreturn]] void rethrow_nested() const;
297
- exception_ptr nested_ptr() const noexcept;
298
  };
299
 
300
- template<class T> [[noreturn]] void throw_with_nested(T&& t);
301
- template<class E> void rethrow_if_nested(const E& e);
302
  }
303
  ```
304
 
305
  The class `nested_exception` is designed for use as a mixin through
306
  multiple inheritance. It captures the currently handled exception and
@@ -309,33 +331,33 @@ stores it for later use.
309
  [*Note 1*: `nested_exception` has a virtual destructor to make it a
310
  polymorphic class. Its presence can be tested for with
311
  `dynamic_cast`. — *end note*]
312
 
313
  ``` cpp
314
- nested_exception() noexcept;
315
  ```
316
 
317
  *Effects:* The constructor calls `current_exception()` and stores the
318
  returned value.
319
 
320
  ``` cpp
321
- [[noreturn]] void rethrow_nested() const;
322
  ```
323
 
324
  *Effects:* If `nested_ptr()` returns a null pointer, the function calls
325
  the function `std::terminate`. Otherwise, it throws the stored exception
326
  captured by `*this`.
327
 
328
  ``` cpp
329
- exception_ptr nested_ptr() const noexcept;
330
  ```
331
 
332
  *Returns:* The stored exception captured by this `nested_exception`
333
  object.
334
 
335
  ``` cpp
336
- template<class T> [[noreturn]] void throw_with_nested(T&& t);
337
  ```
338
 
339
  Let `U` be `decay_t<T>`.
340
 
341
  *Preconditions:* `U` meets the *Cpp17CopyConstructible* requirements.
@@ -345,11 +367,11 @@ Let `U` be `decay_t<T>`.
345
  is `true`, an exception of unspecified type that is publicly derived
346
  from both `U` and `nested_exception` and constructed from
347
  `std::forward<T>(t)`, otherwise `std::forward<T>(t)`.
348
 
349
  ``` cpp
350
- template<class E> void rethrow_if_nested(const E& e);
351
  ```
352
 
353
  *Effects:* If `E` is not a polymorphic class type, or if
354
  `nested_exception` is an inaccessible or ambiguous base class of `E`,
355
  there is no effect. Otherwise, performs:
 
17
  using terminate_handler = void (*)();
18
  terminate_handler get_terminate() noexcept;
19
  terminate_handler set_terminate(terminate_handler f) noexcept;
20
  [[noreturn]] void terminate() noexcept;
21
 
22
+ constexpr int uncaught_exceptions() noexcept;
23
 
24
  using exception_ptr = unspecified;
25
 
26
+ constexpr exception_ptr current_exception() noexcept;
27
+ [[noreturn]] constexpr void rethrow_exception(exception_ptr p);
28
+ template<class E> constexpr exception_ptr make_exception_ptr(E e) noexcept;
29
+ template<class E> constexpr const E* exception_ptr_cast(const exception_ptr& p) noexcept;
30
+ template<class E> void exception_ptr_cast(const exception_ptr&&) = delete;
31
 
32
+ template<class T> [[noreturn]] constexpr void throw_with_nested(T&& t);
33
+ template<class E> constexpr void rethrow_if_nested(const E& e);
34
  }
35
  ```
36
 
37
  ### Class `exception` <a id="exception">[[exception]]</a>
38
 
39
  ``` cpp
40
  namespace std {
41
  class exception {
42
  public:
43
+ constexpr exception() noexcept;
44
+ constexpr exception(const exception&) noexcept;
45
+ constexpr exception& operator=(const exception&) noexcept;
46
+ constexpr virtual ~exception();
47
+ constexpr virtual const char* what() const noexcept;
48
  };
49
  }
50
  ```
51
 
52
  The class `exception` defines the base class for the types of objects
53
  thrown as exceptions by C++ standard library components, and certain
54
  expressions, to report errors detected during program execution.
55
 
56
+ Except where explicitly specified otherwise, each standard library class
57
+ `T` that derives from class `exception` has the following publicly
58
+ accessible member functions, each of them having a non-throwing
59
+ exception specification [[except.spec]]:
60
 
61
  - default constructor (unless the class synopsis shows other
62
  constructors)
63
  - copy constructor
64
  - copy assignment operator
 
68
  and `lhs` is a copy of `rhs`, then `strcmp(lhs.what(), rhs.what())` is
69
  equal to `0`. The `what()` member function of each such `T` satisfies
70
  the constraints specified for `exception::what()` (see below).
71
 
72
  ``` cpp
73
+ constexpr exception(const exception& rhs) noexcept;
74
+ constexpr exception& operator=(const exception& rhs) noexcept;
75
  ```
76
 
77
  *Ensures:* If `*this` and `rhs` both have dynamic type `exception` then
78
  the value of the expression `strcmp(what(), rhs.what())` shall equal 0.
79
 
80
  ``` cpp
81
+ constexpr virtual ~exception();
82
  ```
83
 
84
  *Effects:* Destroys an object of class `exception`.
85
 
86
  ``` cpp
87
+ constexpr virtual const char* what() const noexcept;
88
  ```
89
 
90
+ *Returns:* An *implementation-defined* NTBS, which during constant
91
+ evaluation is encoded with the ordinary literal encoding [[lex.ccon]].
92
 
93
  *Remarks:* The message may be a null-terminated multibyte
94
  string [[multibyte.strings]], suitable for conversion and display as a
95
  `wstring` [[string.classes]], [[locale.codecvt]]. The return value
96
  remains valid until the exception object from which it is obtained is
 
102
  ``` cpp
103
  namespace std {
104
  class bad_exception : public exception {
105
  public:
106
  // see [exception] for the specification of the special member functions
107
+ constexpr const char* what() const noexcept override;
108
  };
109
  }
110
  ```
111
 
112
  The class `bad_exception` defines the type of the object referenced by
113
  the `exception_ptr` returned from a call to `current_exception`
114
  [[propagation]] when the currently active exception object fails to
115
  copy.
116
 
117
  ``` cpp
118
+ constexpr const char* what() const noexcept override;
119
  ```
120
 
121
  *Returns:* An *implementation-defined* NTBS.
122
 
123
  ### Abnormal termination <a id="exception.terminate">[[exception.terminate]]</a>
 
180
  called directly by the program.
181
 
182
  ### `uncaught_exceptions` <a id="uncaught.exceptions">[[uncaught.exceptions]]</a>
183
 
184
  ``` cpp
185
+ constexpr int uncaught_exceptions() noexcept;
186
  ```
187
 
188
+ *Returns:* The number of uncaught exceptions [[except.throw]] in the
189
+ current thread.
190
 
191
  *Remarks:* When `uncaught_exceptions() > 0`, throwing an exception can
192
  result in a call of the function `std::terminate` [[except.terminate]].
193
 
194
  ### Exception propagation <a id="propagation">[[propagation]]</a>
 
215
  as `exception_ptr`. — *end note*]
216
 
217
  For purposes of determining the presence of a data race, operations on
218
  `exception_ptr` objects shall access and modify only the `exception_ptr`
219
  objects themselves and not the exceptions they refer to. Use of
220
+ `rethrow_exception` or `exception_ptr_cast` on `exception_ptr` objects
221
+ that refer to the same exception object shall not introduce a data race.
222
 
223
  [*Note 2*: If `rethrow_exception` rethrows the same exception object
224
  (rather than a copy), concurrent access to that rethrown exception
225
  object can introduce a data race. Changes in the number of
226
  `exception_ptr` objects that refer to a particular exception do not
227
  introduce a data race. — *end note*]
228
 
229
+ All member functions are marked `constexpr`.
230
+
231
  ``` cpp
232
+ constexpr exception_ptr current_exception() noexcept;
233
  ```
234
 
235
  *Returns:* An `exception_ptr` object that refers to the currently
236
  handled exception [[except.handle]] or a copy of the currently handled
237
  exception, or a null `exception_ptr` object if no exception is being
 
249
  the function returns an `exception_ptr` object that refers to the thrown
250
  exception or, if this is not possible, to an instance of
251
  `bad_exception`.
252
 
253
  [*Note 4*: The copy constructor of the thrown exception can also fail,
254
+ so the implementation can substitute a `bad_exception` object to avoid
255
+ infinite recursion. — *end note*]
256
 
257
  ``` cpp
258
+ [[noreturn]] constexpr void rethrow_exception(exception_ptr p);
259
  ```
260
 
261
  *Preconditions:* `p` is not a null pointer.
262
 
263
  *Effects:* Let u be the exception object to which `p` refers, or a copy
 
269
  - otherwise, if copying the exception to which `p` refers to form u
270
  throws an exception, throws that exception;
271
  - otherwise, throws u.
272
 
273
  ``` cpp
274
+ template<class E> constexpr exception_ptr make_exception_ptr(E e) noexcept;
275
  ```
276
 
277
  *Effects:* Creates an `exception_ptr` object that refers to a copy of
278
  `e`, as if:
279
 
 
286
  ```
287
 
288
  [*Note 5*: This function is provided for convenience and efficiency
289
  reasons. — *end note*]
290
 
291
+ ``` cpp
292
+ template<class E> constexpr const E* exception_ptr_cast(const exception_ptr& p) noexcept;
293
+ ```
294
+
295
+ *Mandates:* `E` is a cv-unqualified complete object type. `E` is not an
296
+ array type. `E` is not a pointer or pointer-to-member type.
297
+
298
+ [*Note 6*: When `E` is a pointer or pointer-to-member type, a handler
299
+ of type `const E&` can match without binding to the exception object
300
+ itself. — *end note*]
301
+
302
+ *Returns:* A pointer to the exception object referred to by `p`, if `p`
303
+ is not null and a handler of type `const E&` would be a
304
+ match [[except.handle]] for that exception object. Otherwise, `nullptr`.
305
+
306
  ### `nested_exception` <a id="except.nested">[[except.nested]]</a>
307
 
308
  ``` cpp
309
  namespace std {
310
  class nested_exception {
311
  public:
312
+ constexpr nested_exception() noexcept;
313
+ constexpr nested_exception(const nested_exception&) noexcept = default;
314
+ constexpr nested_exception& operator=(const nested_exception&) noexcept = default;
315
+ constexpr virtual ~nested_exception() = default;
316
 
317
  // access functions
318
+ [[noreturn]] constexpr void rethrow_nested() const;
319
+ constexpr exception_ptr nested_ptr() const noexcept;
320
  };
321
 
322
+ template<class T> [[noreturn]] constexpr void throw_with_nested(T&& t);
323
+ template<class E> constexpr void rethrow_if_nested(const E& e);
324
  }
325
  ```
326
 
327
  The class `nested_exception` is designed for use as a mixin through
328
  multiple inheritance. It captures the currently handled exception and
 
331
  [*Note 1*: `nested_exception` has a virtual destructor to make it a
332
  polymorphic class. Its presence can be tested for with
333
  `dynamic_cast`. — *end note*]
334
 
335
  ``` cpp
336
+ constexpr nested_exception() noexcept;
337
  ```
338
 
339
  *Effects:* The constructor calls `current_exception()` and stores the
340
  returned value.
341
 
342
  ``` cpp
343
+ [[noreturn]] constexpr void rethrow_nested() const;
344
  ```
345
 
346
  *Effects:* If `nested_ptr()` returns a null pointer, the function calls
347
  the function `std::terminate`. Otherwise, it throws the stored exception
348
  captured by `*this`.
349
 
350
  ``` cpp
351
+ constexpr exception_ptr nested_ptr() const noexcept;
352
  ```
353
 
354
  *Returns:* The stored exception captured by this `nested_exception`
355
  object.
356
 
357
  ``` cpp
358
+ template<class T> [[noreturn]] constexpr void throw_with_nested(T&& t);
359
  ```
360
 
361
  Let `U` be `decay_t<T>`.
362
 
363
  *Preconditions:* `U` meets the *Cpp17CopyConstructible* requirements.
 
367
  is `true`, an exception of unspecified type that is publicly derived
368
  from both `U` and `nested_exception` and constructed from
369
  `std::forward<T>(t)`, otherwise `std::forward<T>(t)`.
370
 
371
  ``` cpp
372
+ template<class E> constexpr void rethrow_if_nested(const E& e);
373
  ```
374
 
375
  *Effects:* If `E` is not a polymorphic class type, or if
376
  `nested_exception` is an inaccessible or ambiguous base class of `E`,
377
  there is no effect. Otherwise, performs: