Skip to content

Commit 3cd3ca5

Browse files
authored
Merge 2022-02 LWG Motion 4
P0627R6 Function to mark unreachable code
2 parents 80cbaf7 + 82ebf56 commit 3cd3ca5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@
707707
#define @\defnlibxname{cpp_lib_type_trait_variable_templates}@ 201510L // also in \libheader{type_traits}
708708
#define @\defnlibxname{cpp_lib_uncaught_exceptions}@ 201411L // also in \libheader{exception}
709709
#define @\defnlibxname{cpp_lib_unordered_map_try_emplace}@ 201411L // also in \libheader{unordered_map}
710+
#define @\defnlibxname{cpp_lib_unreachable}@ 202202L // also in \libheader{utility}
710711
#define @\defnlibxname{cpp_lib_unwrap_ref}@ 201811L // also in \libheader{type_traits}
711712
#define @\defnlibxname{cpp_lib_variant}@ 202106L // also in \libheader{variant}
712713
#define @\defnlibxname{cpp_lib_void_t}@ 201411L // also in \libheader{type_traits}

source/utilities.tex

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
template<class T>
100100
constexpr underlying_type_t<T> to_underlying(T value) noexcept;
101101

102+
// \ref{utility.unreachable}, unreachable
103+
[[noreturn]] void unreachable();
104+
102105
// \ref{intseq}, compile-time integer sequences%
103106
\indexlibraryglobal{index_sequence}%
104107
\indexlibraryglobal{make_index_sequence}%
@@ -611,6 +614,39 @@
611614
\tcode{static_cast<underlying_type_t<T>>(value)}.
612615
\end{itemdescr}
613616

617+
\rSec2[utility.unreachable]{Function \tcode{unreachable}}
618+
619+
\indexlibraryglobal{unreachable}%
620+
\begin{itemdecl}
621+
[[noreturn]] void unreachable();
622+
\end{itemdecl}
623+
624+
\begin{itemdescr}
625+
\pnum
626+
\expects
627+
\tcode{false} is \tcode{true}.
628+
\begin{note}
629+
This precondition cannot be satisfied, thus the behavior
630+
of calling \tcode{unreachable} is undefined.
631+
\end{note}
632+
633+
\pnum
634+
\begin{example}
635+
\begin{codeblock}
636+
int f(int x) {
637+
switch (x) {
638+
case 0:
639+
case 1:
640+
return x;
641+
default:
642+
std::unreachable();
643+
}
644+
}
645+
int a = f(1); // OK, \tcode{a} has value \tcode{1}
646+
int b = f(3); // undefined behavior
647+
\end{codeblock}
648+
\end{example}
649+
\end{itemdescr}
614650

615651
\rSec1[intseq]{Compile-time integer sequences}
616652

0 commit comments

Comments
 (0)