Skip to content

Commit 0af557a

Browse files
committed
New issue from Lénárd Szolnoki: "Unconditionally constexpr current_exception()"
1 parent f4b7b2a commit 0af557a

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

xml/issue4361.xml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4361" status="New">
5+
<title>Unconditionally `constexpr current_exception()`</title>
6+
<section>
7+
<sref ref="[propagation]"/>
8+
</section>
9+
<submitter>Lénárd Szolnoki</submitter>
10+
<date>27 Aug 2025</date>
11+
<priority>99</priority>
12+
13+
<discussion>
14+
<p>
15+
The declaration of `current_exception()`:
16+
</p>
17+
<blockquote><pre>
18+
constexpr exception_ptr current_exception() noexcept;
19+
</pre></blockquote>
20+
<p>
21+
The `constexpr` specifier is in the current draft <paper num="N5014"/>, introduced by <paper num="P3068"/>
22+
targeting C++26.
23+
<p/>
24+
It is not constrained when the expression `std::current_exception()` is constant. Consider:
25+
</p>
26+
<blockquote><pre>
27+
try {
28+
throw 0;
29+
} catch (int) {
30+
const bool b = (std::current_exception() != nullptr);
31+
}
32+
</pre></blockquote>
33+
<p>
34+
Since `b` is a variable of constant integral type, it is potentially-constant and its initialization
35+
goes trough trial constant evaluation. `std::current_exception()` can't be implemented to return an
36+
`exception_ptr` that refers to the runtime exception here during constant evaluation, so it returns
37+
a null `exception_ptr` and `b` gets initialized to `false`. This is a breaking change compared to
38+
C++23, where `b` is initialized to `true`.
39+
</p>
40+
</discussion>
41+
42+
<resolution>
43+
<p>
44+
This wording is relative to <paper num="N5014"/>.
45+
</p>
46+
47+
<blockquote class="note">
48+
<p>
49+
[<i>Drafting Note:</i> Two mutually exclusive options are prepared, depicted below by <b>Option A</b> and
50+
<b>Option B</b>, respectively.]
51+
</p>
52+
</blockquote>
53+
54+
<p>
55+
<b>Option A:</b>
56+
</p>
57+
58+
<ol>
59+
60+
<li><p>Modify <sref ref="[propagation]"/> as indicated:</p>
61+
62+
<blockquote>
63+
<pre>
64+
constexpr exception_ptr current_exception() noexcept;
65+
</pre>
66+
<blockquote>
67+
<p>
68+
<ins><i>Constant When</i>: If there is a currently handled exception that was originally thrown within
69+
the current constant evaluation.</ins>
70+
<p/>
71+
-9- <i>Returns</i>: [&hellip;]
72+
</p>
73+
</blockquote>
74+
</blockquote>
75+
76+
</li>
77+
78+
</ol>
79+
80+
<p>
81+
<b>Option B:</b>
82+
</p>
83+
84+
<ol>
85+
86+
<li><p>Modify <sref ref="[propagation]"/> as indicated:</p>
87+
88+
<blockquote>
89+
<pre>
90+
constexpr exception_ptr current_exception() noexcept;
91+
</pre>
92+
<blockquote>
93+
<p>
94+
<ins><i>Constant When</i>: Current constant evaluation is not part of potentially-constant initialization
95+
of a non-static variable.</ins>
96+
<p/>
97+
-9- <i>Returns</i>: [&hellip;]
98+
</p>
99+
</blockquote>
100+
</blockquote>
101+
102+
</li>
103+
104+
</ol>
105+
</resolution>
106+
107+
</issue>

0 commit comments

Comments
 (0)