File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 707
707
#define @\defnlibxname {cpp_lib_type_trait_variable_templates}@ 201510L // also in \libheader {type_traits}
708
708
#define @\defnlibxname {cpp_lib_uncaught_exceptions}@ 201411L // also in \libheader {exception}
709
709
#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}
710
711
#define @\defnlibxname {cpp_lib_unwrap_ref}@ 201811L // also in \libheader {type_traits}
711
712
#define @\defnlibxname {cpp_lib_variant}@ 202106L // also in \libheader {variant}
712
713
#define @\defnlibxname {cpp_lib_void_t}@ 201411L // also in \libheader {type_traits}
Original file line number Diff line number Diff line change 99
99
template<class T>
100
100
constexpr underlying_type_t<T> to_underlying(T value) noexcept;
101
101
102
+ // \ref{utility.unreachable}, unreachable
103
+ [[noreturn]] void unreachable();
104
+
102
105
// \ref{intseq}, compile-time integer sequences%
103
106
\indexlibraryglobal{index_sequence}%
104
107
\indexlibraryglobal{make_index_sequence}%
611
614
\tcode{static_cast<underlying_type_t<T>>(value)}.
612
615
\end{itemdescr}
613
616
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}
614
650
615
651
\rSec1[intseq]{Compile-time integer sequences}
616
652
You can’t perform that action at this time.
0 commit comments