This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

208
cppdraft/propagation.md Normal file
View File

@@ -0,0 +1,208 @@
[propagation]
# 17 Language support library [[support]](./#support)
## 17.9 Exception handling [[support.exception]](support.exception#propagation)
### 17.9.7 Exception propagation [propagation]
[🔗](#lib:exception_ptr)
`using exception_ptr = unspecified;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4121)
The type exception_ptr can be used to refer to an exception object[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4124)
exception_ptr meets the requirements of[*Cpp17NullablePointer*](nullablepointer.requirements#:Cpp17NullablePointer "16.4.4.4Cpp17NullablePointer requirements[nullablepointer.requirements]") (Table [36](nullablepointer.requirements#tab:cpp17.nullablepointer "Table 36: Cpp17NullablePointer requirements"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4128)
Two non-null values of type exception_ptr are equivalent and compare equal if and
only if they refer to the same exception[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4132)
The default constructor of exception_ptr produces the null value of the
type[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4136)
exception_ptr shall not be implicitly convertible to any arithmetic,
enumeration, or pointer type[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4140)
[*Note [1](#note-1)*:
An implementation can use a reference-counted smart
pointer as exception_ptr[.](#6.sentence-1)
— *end note*]
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4146)
For purposes of determining the presence of a data race, operations onexception_ptr objects shall access and modify only theexception_ptr objects themselves and not the exceptions they refer to[.](#7.sentence-1)
Use of rethrow_exception or exception_ptr_cast on exception_ptr objects that refer to
the same exception object shall not introduce a data race[.](#7.sentence-2)
[*Note [2](#note-2)*:
Ifrethrow_exception rethrows the same exception object (rather than a copy),
concurrent access to that rethrown exception object can introduce a data race[.](#7.sentence-3)
Changes in the number of exception_ptr objects that refer to a
particular exception do not introduce a data race[.](#7.sentence-4)
— *end note*]
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4161)
All member functions are marked constexpr[.](#8.sentence-1)
[🔗](#lib:current_exception)
`constexpr exception_ptr current_exception() noexcept;
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4171)
*Returns*: An exception_ptr object that refers to the[currently handled exception](except.handle#def:exception_handling,currently_handled_exception "14.4Handling an exception[except.handle]") or a copy of the currently
handled exception, or a null exception_ptr object if no exception is being
handled[.](#9.sentence-1)
The referenced object shall remain valid at least as long as there is anexception_ptr object that refers to it[.](#9.sentence-2)
If the function needs to allocate memory and the attempt fails, it returns anexception_ptr object that refers to an instance of bad_alloc[.](#9.sentence-3)
It is unspecified whether the return values of two successive calls tocurrent_exception refer to the same exception object[.](#9.sentence-4)
[*Note [3](#note-3)*:
That is, it is unspecified whether current_exception creates a new copy each time it is called[.](#9.sentence-5)
— *end note*]
If the attempt to copy the current exception object throws an exception, the function
returns an exception_ptr object that refers to the thrown exception or,
if this is not possible, to an instance of bad_exception[.](#9.sentence-6)
[*Note [4](#note-4)*:
The copy constructor of the thrown exception can also fail,
so the implementation can substitute a bad_exception object
to avoid infinite recursion[.](#9.sentence-7)
— *end note*]
[🔗](#lib:rethrow_exception)
`[[noreturn]] constexpr void rethrow_exception(exception_ptr p);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4203)
*Preconditions*: p is not a null pointer[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4207)
*Effects*: Let u be the exception object to which p refers, or
a copy of that exception object[.](#11.sentence-1)
It is unspecified whether a copy is made, and
memory for the copy is allocated in an unspecified way[.](#11.sentence-2)
- [(11.1)](#11.1)
If allocating memory to form u fails,
throws an instance of bad_alloc;
- [(11.2)](#11.2)
otherwise, if copying the exception to which p refers
to form u throws an exception, throws that exception;
- [(11.3)](#11.3)
otherwise, throws u.
[🔗](#lib:make_exception_ptr)
`template<class E> constexpr exception_ptr make_exception_ptr(E e) noexcept;
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4231)
*Effects*: Creates an exception_ptr object that refers to a copy of e, as if:try {throw e;} catch(...) {return current_exception();}
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4242)
[*Note [5](#note-5)*:
This function is provided for convenience and
efficiency reasons[.](#13.sentence-1)
— *end note*]
[🔗](#lib:exception_ptr_cast)
`template<class E> constexpr const E* exception_ptr_cast(const exception_ptr& p) noexcept;
`
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4255)
*Mandates*: E is a cv-unqualified complete object type[.](#14.sentence-1)
E is not an array type[.](#14.sentence-2)
E is not a pointer or pointer-to-member type[.](#14.sentence-3)
[*Note [6](#note-6)*:
When E is a pointer or pointer-to-member type,
a handler of type const E& can match
without binding to the exception object itself[.](#14.sentence-4)
— *end note*]
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4266)
*Returns*: A pointer to the exception object referred to by p,
if p is not null and
a handler of type const E& would be a match ([[except.handle]](except.handle "14.4Handling an exception")) for that exception object[.](#15.sentence-1)
Otherwise, nullptr[.](#15.sentence-2)