From 6e148dbf4fd8369cb51f9e2dbbad67a40b141a63 Mon Sep 17 00:00:00 2001 From: Eisenwave Date: Thu, 10 Jul 2025 20:22:35 +0200 Subject: [PATCH] P3560R2 Error Handling in Reflection --- source/meta.tex | 132 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/source/meta.tex b/source/meta.tex index fe90847f6d..3ac8ec0cda 100644 --- a/source/meta.tex +++ b/source/meta.tex @@ -2582,6 +2582,9 @@ namespace std::meta { using info = decltype(^^::); + // \ref{meta.reflection.exception}, class \tcode{exception} + class exception; + // \ref{meta.reflection.operators}, operator representations enum class operators { @\seebelow@; @@ -2972,6 +2975,135 @@ \end{codeblock} \end{example} +\rSec2[meta.reflection.exception]{Class \tcode{exception}} + +\indexlibraryglobal{exception}% +\begin{itemdecl} +class exception : public std::exception +{ +private: + optional @\exposid{what_}@; // \expos + u8string @\exposid{u8what_}@; // \expos + info @\exposid{from_}@; // \expos + source_location @\exposid{where_}@; // \expos + +public: + consteval exception(u8string_view what, info from, + source_location where = source_location::current()) noexcept; + + consteval exception(string_view what, info from, + source_location where = source_location::current()) noexcept; + + exception(const exception&) = default; + exception(exception&&) = default; + + exception& operator=(const exception&) = default; + exception& operator=(exception&&) = default; + + constexpr const char* what() const noexcept override; + consteval u8string_view u8what() const noexcept; + consteval info from() const noexcept; + consteval source_location where() const noexcept; +}; +\end{itemdecl} + +\begin{itemdescr} +\pnum +Reflection functions throw exceptions of type \tcode{meta::exception} +to signal an error. +\tcode{meta::exception} is a consteval-only type. +\end{itemdescr} + +\indexlibraryctor{exception}% +\begin{itemdecl} +consteval exception(u8string_view what, info from, + source_location where = source_location::current()) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Initializes +\exposid{u8what_} with \tcode{what}, +\exposid{from_} with \tcode{from}, and +\exposid{where_} with \tcode{where}. +If \tcode{what} can be represented in the ordinary literal encoding, +initializes \exposid{what_} with \tcode{what}, +transcoded from UTF-8 to the ordinary literal encoding. +Otherwhise, \exposid{what_} is value-initialized. +\end{itemdescr} + +\indexlibraryctor{exception}% +\begin{itemdecl} +consteval exception(string_view what, info from, + source_location where = source_location::current()) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constantwhen +\tcode{what} designates a sequence of characters +that can be encoded in UTF-8. + +\pnum +\effects +Initializes +\exposid{what_} with \tcode{what}, +\exposid{u8what_} with \tcode{what} +transcoded from the ordinary literal encoding to UTF-8, +%FIXME: Oxford comma before "and" +\exposid{from_} with \tcode{from} and +\exposid{where_} with \tcode{where}. +\end{itemdescr} + +\indexlibrarymember{what}{exception}% +\begin{itemdecl} +constexpr const char* what() const noexcept override; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constantwhen +\tcode{\exposid{what_}.has_value()} is \tcode{true}. + +\pnum +\returns +\tcode{\exposid{what_}->c_str()}. +\end{itemdescr} + +\indexlibrarymember{u8what}{exception}% +\begin{itemdecl} +consteval u8string_view what() const noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +\exposid{u8what_}. +\end{itemdescr} + +\indexlibrarymember{from}{exception}% +\begin{itemdecl} +consteval info from() const noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +\exposid{from_}. +\end{itemdescr} + +\indexlibrarymember{where}{exception}% +\begin{itemdecl} +consteval source_location where() const noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +\exposid{where_}. +\end{itemdescr} + \rSec2[meta.reflection.operators]{Operator representations} \begin{itemdecl}