Skip to content

Commit a47f699

Browse files
committed
P0627R6 Function to mark unreachable code
1 parent 4b1a735 commit a47f699

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
@@ -706,6 +706,7 @@
706706
#define @\defnlibxname{cpp_lib_type_trait_variable_templates}@ 201510L // also in \libheader{type_traits}
707707
#define @\defnlibxname{cpp_lib_uncaught_exceptions}@ 201411L // also in \libheader{exception}
708708
#define @\defnlibxname{cpp_lib_unordered_map_try_emplace}@ 201411L // also in \libheader{unordered_map}
709+
#define @\defnlibxname{cpp_lib_unreachable}@ 202202L // also in \libheader{utility}
709710
#define @\defnlibxname{cpp_lib_unwrap_ref}@ 201811L // also in \libheader{type_traits}
710711
#define @\defnlibxname{cpp_lib_variant}@ 202106L // also in \libheader{variant}
711712
#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
@@ -98,6 +98,9 @@
9898
template<class T>
9999
constexpr underlying_type_t<T> to_underlying(T value) noexcept;
100100

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

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

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

0 commit comments

Comments
 (0)