Skip to content

Commit deeb9a9

Browse files
committed
P3068R6 Allowing exception throwing in constant-evaluation
1 parent aed9756 commit deeb9a9

File tree

3 files changed

+65
-48
lines changed

3 files changed

+65
-48
lines changed

source/expressions.tex

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7690,6 +7690,13 @@
76907690
unless it deallocates a region of storage
76917691
allocated within the evaluation of $E$;
76927692

7693+
\item
7694+
a construction of an exception object,
7695+
unless the exception object and
7696+
all of its implicit copies created by invocations of
7697+
\tcode{std::current_exception} or \tcode{std::rethrow_exception}\iref{propagation}
7698+
are destroyed within the evaluation of $E$;
7699+
76937700
\item
76947701
an \grammarterm{await-expression}\iref{expr.await};
76957702

@@ -7701,15 +7708,18 @@
77017708
relational\iref{expr.rel}, or equality\iref{expr.eq}
77027709
operator where the result is unspecified;
77037710

7704-
\item
7705-
a \grammarterm{throw-expression}\iref{expr.throw};
7706-
77077711
\item
77087712
a \keyword{dynamic_cast}\iref{expr.dynamic.cast} or
77097713
\keyword{typeid}\iref{expr.typeid} expression
77107714
on a glvalue that refers to an object
7711-
whose dynamic type is constexpr-unknown or
7712-
that would throw an exception;
7715+
whose dynamic type is constexpr-unknown;
7716+
7717+
\item
7718+
a \tcode{dynamic_cast}\iref{expr.dynamic.cast} expression,
7719+
\tcode{typeid}\iref{expr.typeid} expression, or
7720+
\tcode{new-expression}\iref{expr.new}
7721+
that would throw an exception
7722+
where no definition of the exception type is reachable;
77137723

77147724
\item
77157725
an \grammarterm{asm-declaration}\iref{dcl.asm};

source/preprocessor.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,7 @@
18501850
\defnxname{cpp_conditional_explicit} & \tcode{201806L} \\ \rowsep
18511851
\defnxname{cpp_constexpr} & \tcode{202406L} \\ \rowsep
18521852
\defnxname{cpp_constexpr_dynamic_alloc} & \tcode{201907L} \\ \rowsep
1853+
\defnxname{cpp_constexpr_exceptions} & \tcode{202411L} \\ \rowsep
18531854
\defnxname{cpp_constexpr_in_decltype} & \tcode{201711L} \\ \rowsep
18541855
\defnxname{cpp_consteval} & \tcode{202211L} \\ \rowsep
18551856
\defnxname{cpp_constinit} & \tcode{201907L} \\ \rowsep

source/support.tex

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@
607607
#define @\defnlibxname{cpp_lib_constexpr_cmath}@ 202306L // also in \libheader{cmath}, \libheader{cstdlib}
608608
#define @\defnlibxname{cpp_lib_constexpr_complex}@ 202306L // also in \libheader{complex}
609609
#define @\defnlibxname{cpp_lib_constexpr_dynamic_alloc}@ 201907L // also in \libheader{memory}
610+
#define @\defnlibxname{cpp_lib_constexpr_exceptions}@ 202411L // also in \libheader{exception}
610611
#define @\defnlibxname{cpp_lib_constexpr_functional}@ 201907L // freestanding, also in \libheader{functional}
611612
#define @\defnlibxname{cpp_lib_constexpr_iterator}@ 201811L // freestanding, also in \libheader{iterator}
612613
#define @\defnlibxname{cpp_lib_constexpr_memory}@ 202202L // freestanding, also in \libheader{memory}
@@ -2941,7 +2942,7 @@
29412942
class bad_alloc : public exception {
29422943
public:
29432944
// see \ref{exception} for the specification of the special member functions
2944-
const char* what() const noexcept override;
2945+
constexpr const char* what() const noexcept override;
29452946
};
29462947
}
29472948
\end{codeblock}
@@ -2954,7 +2955,7 @@
29542955

29552956
\indexlibrarymember{what}{bad_alloc}%
29562957
\begin{itemdecl}
2957-
const char* what() const noexcept override;
2958+
constexpr const char* what() const noexcept override;
29582959
\end{itemdecl}
29592960

29602961
\begin{itemdescr}
@@ -2972,7 +2973,7 @@
29722973
class bad_array_new_length : public bad_alloc {
29732974
public:
29742975
// see \ref{exception} for the specification of the special member functions
2975-
const char* what() const noexcept override;
2976+
constexpr const char* what() const noexcept override;
29762977
};
29772978
}
29782979
\end{codeblock}
@@ -2985,7 +2986,7 @@
29852986

29862987
\indexlibrarymember{what}{bad_array_new_length}%
29872988
\begin{itemdecl}
2988-
const char* what() const noexcept override;
2989+
constexpr const char* what() const noexcept override;
29892990
\end{itemdecl}
29902991

29912992
\begin{itemdescr}
@@ -3310,7 +3311,7 @@
33103311
class bad_cast : public exception {
33113312
public:
33123313
// see \ref{exception} for the specification of the special member functions
3313-
const char* what() const noexcept override;
3314+
constexpr const char* what() const noexcept override;
33143315
};
33153316
}
33163317
\end{codeblock}
@@ -3326,7 +3327,7 @@
33263327

33273328
\indexlibrarymember{what}{bad_cast}%
33283329
\begin{itemdecl}
3329-
const char* what() const noexcept override;
3330+
constexpr const char* what() const noexcept override;
33303331
\end{itemdecl}
33313332

33323333
\begin{itemdescr}
@@ -3344,7 +3345,7 @@
33443345
class bad_typeid : public exception {
33453346
public:
33463347
// see \ref{exception} for the specification of the special member functions
3347-
const char* what() const noexcept override;
3348+
constexpr const char* what() const noexcept override;
33483349
};
33493350
}
33503351
\end{codeblock}
@@ -3360,7 +3361,7 @@
33603361

33613362
\indexlibrarymember{what}{bad_typeid}%
33623363
\begin{itemdecl}
3363-
const char* what() const noexcept override;
3364+
constexpr const char* what() const noexcept override;
33643365
\end{itemdecl}
33653366

33663367
\begin{itemdescr}
@@ -3775,16 +3776,16 @@
37753776
terminate_handler set_terminate(terminate_handler f) noexcept;
37763777
[[noreturn]] void terminate() noexcept;
37773778

3778-
int uncaught_exceptions() noexcept;
3779+
constexpr int uncaught_exceptions() noexcept;
37793780

37803781
using exception_ptr = @\unspec@;
37813782

3782-
exception_ptr current_exception() noexcept;
3783-
[[noreturn]] void rethrow_exception(exception_ptr p);
3784-
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
3783+
constexpr exception_ptr current_exception() noexcept;
3784+
[[noreturn]] constexpr void rethrow_exception(exception_ptr p);
3785+
template<class E> constexpr exception_ptr make_exception_ptr(E e) noexcept;
37853786

3786-
template<class T> [[noreturn]] void throw_with_nested(T&& t);
3787-
template<class E> void rethrow_if_nested(const E& e);
3787+
template<class T> [[noreturn]] constexpr void throw_with_nested(T&& t);
3788+
template<class E> constexpr void rethrow_if_nested(const E& e);
37883789
}
37893790
\end{codeblock}
37903791

@@ -3796,11 +3797,11 @@
37963797
namespace std {
37973798
class exception {
37983799
public:
3799-
exception() noexcept;
3800-
exception(const exception&) noexcept;
3801-
exception& operator=(const exception&) noexcept;
3802-
virtual ~exception();
3803-
virtual const char* what() const noexcept;
3800+
constexpr exception() noexcept;
3801+
constexpr exception(const exception&) noexcept;
3802+
constexpr exception& operator=(const exception&) noexcept;
3803+
constexpr virtual ~exception();
3804+
constexpr virtual const char* what() const noexcept;
38043805
};
38053806
}
38063807
\end{codeblock}
@@ -3833,8 +3834,8 @@
38333834
\indexlibraryctor{exception}%
38343835
\indexlibrarymember{operator=}{exception}%
38353836
\begin{itemdecl}
3836-
exception(const exception& rhs) noexcept;
3837-
exception& operator=(const exception& rhs) noexcept;
3837+
constexpr exception(const exception& rhs) noexcept;
3838+
constexpr exception& operator=(const exception& rhs) noexcept;
38383839
\end{itemdecl}
38393840

38403841
\begin{itemdescr}
@@ -3846,7 +3847,7 @@
38463847

38473848
\indexlibrarydtor{exception}%
38483849
\begin{itemdecl}
3849-
virtual ~exception();
3850+
constexpr virtual ~exception();
38503851
\end{itemdecl}
38513852

38523853
\begin{itemdescr}
@@ -3858,13 +3859,15 @@
38583859

38593860
\indexlibrarymember{what}{exception}%
38603861
\begin{itemdecl}
3861-
virtual const char* what() const noexcept;
3862+
constexpr virtual const char* what() const noexcept;
38623863
\end{itemdecl}
38633864

38643865
\begin{itemdescr}
38653866
\pnum
38663867
\returns
3867-
An \impldef{return value of \tcode{exception::what}} \ntbs{}.
3868+
An \impldef{return value of \tcode{exception::what}} \ntbs{},
3869+
which during constant evaluation is encoded with
3870+
the ordinary literal encoding\iref{lex.ccon}.
38683871

38693872
\pnum
38703873
\remarks
@@ -3885,7 +3888,7 @@
38853888
class bad_exception : public exception {
38863889
public:
38873890
// see \ref{exception} for the specification of the special member functions
3888-
const char* what() const noexcept override;
3891+
constexpr const char* what() const noexcept override;
38893892
};
38903893
}
38913894
\end{codeblock}
@@ -3900,7 +3903,7 @@
39003903

39013904
\indexlibrarymember{what}{bad_exception}%
39023905
\begin{itemdecl}
3903-
const char* what() const noexcept override;
3906+
constexpr const char* what() const noexcept override;
39043907
\end{itemdecl}
39053908

39063909
\begin{itemdescr}
@@ -4007,7 +4010,7 @@
40074010

40084011
\indexlibraryglobal{uncaught_exceptions}%
40094012
\begin{itemdecl}
4010-
int uncaught_exceptions() noexcept;
4013+
constexpr int uncaught_exceptions() noexcept;
40114014
\end{itemdecl}
40124015

40134016
\begin{itemdescr}
@@ -4068,11 +4071,14 @@
40684071
Changes in the number of \tcode{exception_ptr} objects that refer to a
40694072
particular exception do not introduce a data race.
40704073
\end{note}
4074+
4075+
\pnum
4076+
All member functions are marked \tcode{constexpr}.
40714077
\end{itemdescr}
40724078

40734079
\indexlibraryglobal{current_exception}%
40744080
\begin{itemdecl}
4075-
exception_ptr current_exception() noexcept;
4081+
constexpr exception_ptr current_exception() noexcept;
40764082
\end{itemdecl}
40774083

40784084
\begin{itemdescr}
@@ -4103,7 +4109,7 @@
41034109

41044110
\indexlibraryglobal{rethrow_exception}%
41054111
\begin{itemdecl}
4106-
[[noreturn]] void rethrow_exception(exception_ptr p);
4112+
[[noreturn]] constexpr void rethrow_exception(exception_ptr p);
41074113
\end{itemdecl}
41084114

41094115
\begin{itemdescr}
@@ -4131,7 +4137,7 @@
41314137

41324138
\indexlibraryglobal{make_exception_ptr}%
41334139
\begin{itemdecl}
4134-
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
4140+
template<class E> constexpr exception_ptr make_exception_ptr(E e) noexcept;
41354141
\end{itemdecl}
41364142

41374143
\begin{itemdescr}
@@ -4160,18 +4166,18 @@
41604166
namespace std {
41614167
class nested_exception {
41624168
public:
4163-
nested_exception() noexcept;
4164-
nested_exception(const nested_exception&) noexcept = default;
4165-
nested_exception& operator=(const nested_exception&) noexcept = default;
4166-
virtual ~nested_exception() = default;
4169+
constexpr nested_exception() noexcept;
4170+
constexpr nested_exception(const nested_exception&) noexcept = default;
4171+
constexpr nested_exception& operator=(const nested_exception&) noexcept = default;
4172+
constexpr virtual ~nested_exception() = default;
41674173

41684174
// access functions
4169-
[[noreturn]] void rethrow_nested() const;
4170-
exception_ptr nested_ptr() const noexcept;
4175+
[[noreturn]] constexpr void rethrow_nested() const;
4176+
constexpr exception_ptr nested_ptr() const noexcept;
41714177
};
41724178

4173-
template<class T> [[noreturn]] void throw_with_nested(T&& t);
4174-
template<class E> void rethrow_if_nested(const E& e);
4179+
template<class T> [[noreturn]] constexpr void throw_with_nested(T&& t);
4180+
template<class E> constexpr void rethrow_if_nested(const E& e);
41754181
}
41764182
\end{codeblock}
41774183

@@ -4188,7 +4194,7 @@
41884194

41894195
\indexlibraryctor{nested_exception}%
41904196
\begin{itemdecl}
4191-
nested_exception() noexcept;
4197+
constexpr nested_exception() noexcept;
41924198
\end{itemdecl}
41934199

41944200
\begin{itemdescr}
@@ -4199,7 +4205,7 @@
41994205

42004206
\indexlibrarymember{rethrow_nested}{nested_exception}%
42014207
\begin{itemdecl}
4202-
[[noreturn]] void rethrow_nested() const;
4208+
[[noreturn]] constexpr void rethrow_nested() const;
42034209
\end{itemdecl}
42044210

42054211
\begin{itemdescr}
@@ -4211,7 +4217,7 @@
42114217

42124218
\indexlibrarymember{nested_ptr}{nested_exception}%
42134219
\begin{itemdecl}
4214-
exception_ptr nested_ptr() const noexcept;
4220+
constexpr exception_ptr nested_ptr() const noexcept;
42154221
\end{itemdecl}
42164222

42174223
\begin{itemdescr}
@@ -4222,7 +4228,7 @@
42224228

42234229
\indexlibrarymember{throw_with_nested}{nested_exception}%
42244230
\begin{itemdecl}
4225-
template<class T> [[noreturn]] void throw_with_nested(T&& t);
4231+
template<class T> [[noreturn]] constexpr void throw_with_nested(T&& t);
42264232
\end{itemdecl}
42274233

42284234
\begin{itemdescr}
@@ -4245,7 +4251,7 @@
42454251

42464252
\indexlibrarymember{rethrow_if_nested}{nested_exception}%
42474253
\begin{itemdecl}
4248-
template<class E> void rethrow_if_nested(const E& e);
4254+
template<class E> constexpr void rethrow_if_nested(const E& e);
42494255
\end{itemdecl}
42504256

42514257
\begin{itemdescr}

0 commit comments

Comments
 (0)