-
Notifications
You must be signed in to change notification settings - Fork 815
[2026-06 LWG Motion 6] P3395R6 (Fix encoding issues and add a formatter for std::error_code) #9129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4405b34
84ceb13
3670a2c
ab3fc5d
9cadf69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -764,6 +764,9 @@ | |||||||||||||||||||||
| constexpr bool @\libglobal{is_error_code_enum_v}@ = is_error_code_enum<T>::value; | ||||||||||||||||||||||
| template<class T> | ||||||||||||||||||||||
| constexpr bool @\libglobal{is_error_condition_enum_v}@ = is_error_condition_enum<T>::value; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // \ref{syserr.fmt}, formatter | ||||||||||||||||||||||
| template<class T> struct formatter<error_code, charT>; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| \end{codeblock} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -836,7 +839,7 @@ | |||||||||||||||||||||
| \begin{itemdescr} | ||||||||||||||||||||||
| \pnum | ||||||||||||||||||||||
| \returns | ||||||||||||||||||||||
| A string naming the error category. | ||||||||||||||||||||||
| A string in the ordinary literal encoding naming the error category. | ||||||||||||||||||||||
| \end{itemdescr} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \indexlibrarymember{default_error_condition}{error_category}% | ||||||||||||||||||||||
|
|
@@ -880,7 +883,8 @@ | |||||||||||||||||||||
| \begin{itemdescr} | ||||||||||||||||||||||
| \pnum | ||||||||||||||||||||||
| \returns | ||||||||||||||||||||||
| A string that describes the error condition denoted by \tcode{ev}. | ||||||||||||||||||||||
| A string of multibyte characters in the execution character set | ||||||||||||||||||||||
| that describes the error condition denoted by \tcode{ev}. | ||||||||||||||||||||||
| \end{itemdescr} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \rSec3[syserr.errcat.nonvirtuals]{Non-virtual members} | ||||||||||||||||||||||
|
|
@@ -1235,6 +1239,98 @@ | |||||||||||||||||||||
| Equivalent to: \tcode{return os << ec.category().name() << ':' << ec.value();} | ||||||||||||||||||||||
| \end{itemdescr} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \rSec3[syserr.fmt]{Formatting} | ||||||||||||||||||||||
| \pnum | ||||||||||||||||||||||
| \indexlibraryglobal{formatter}% | ||||||||||||||||||||||
| \begin{codeblock} | ||||||||||||||||||||||
| template<class charT> struct formatter<error_code, charT> { | ||||||||||||||||||||||
| constexpr void set_debug_format(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| constexpr typename basic_format_parse_context<charT>::iterator | ||||||||||||||||||||||
| parse(basic_format_parse_context<charT>& ctx); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| template<class Out> | ||||||||||||||||||||||
| typename basic_format_context<Out, charT>::iterator | ||||||||||||||||||||||
| format(const error_code& ec, basic_format_context<Out, charT>& ctx) const; | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| \end{codeblock} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \indexlibrarymember{set_debug_format}{formatter}% | ||||||||||||||||||||||
| \begin{itemdecl} | ||||||||||||||||||||||
| constexpr void set_debug_format(); | ||||||||||||||||||||||
| \end{itemdecl} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \begin{itemdescr} | ||||||||||||||||||||||
| \pnum | ||||||||||||||||||||||
| \effects | ||||||||||||||||||||||
| Modifies the state of the \tcode{formatter} to be as if the | ||||||||||||||||||||||
| \fmtgrammarterm{error-code-format-spec} parsed by the | ||||||||||||||||||||||
| last call to \tcode{parse} contained the \tcode{?} option. | ||||||||||||||||||||||
| \end{itemdescr} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \indexlibrarymember{parse}{formatter}% | ||||||||||||||||||||||
| \begin{itemdecl} | ||||||||||||||||||||||
| constexpr typename basic_format_parse_context<charT>::iterator | ||||||||||||||||||||||
| parse(basic_format_parse_context<charT>& ctx); | ||||||||||||||||||||||
| \end{itemdecl} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \begin{itemdescr} | ||||||||||||||||||||||
| \pnum | ||||||||||||||||||||||
| \effects | ||||||||||||||||||||||
| Parses the format specifier as an \fmtgrammarterm{error-code-format-spec} | ||||||||||||||||||||||
| and stores the parsed specifiers in \tcode{*this}. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \begin{ncbnf} | ||||||||||||||||||||||
| \fmtnontermdef{error-code-format-spec}\br | ||||||||||||||||||||||
| \opt{fill-and-align} \opt{width} \opt{\tcode{?}} \opt{\tcode{s}} | ||||||||||||||||||||||
| \end{ncbnf} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| where the productions \fmtgrammarterm{fill-and-align} and \fmtgrammarterm{width} are | ||||||||||||||||||||||
| described in \ref{format.string}. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \pnum | ||||||||||||||||||||||
| \returns | ||||||||||||||||||||||
| An iterator past the end of the \fmtgrammarterm{error-code-format-spec}. | ||||||||||||||||||||||
| \end{itemdescr} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \indexlibrarymember{format}{formatter}% | ||||||||||||||||||||||
| \begin{itemdecl} | ||||||||||||||||||||||
| template<class Out> | ||||||||||||||||||||||
| typename basic_format_context<Out, charT>::iterator | ||||||||||||||||||||||
| format(const error_code& ec, basic_format_context<Out, charT>& ctx) const; | ||||||||||||||||||||||
| \end{itemdecl} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \begin{itemdescr} | ||||||||||||||||||||||
| \pnum | ||||||||||||||||||||||
| \effects | ||||||||||||||||||||||
| \begin{itemize} | ||||||||||||||||||||||
| \item | ||||||||||||||||||||||
| If the \tcode{s} option is used, then: | ||||||||||||||||||||||
| \begin{itemize} | ||||||||||||||||||||||
| \item | ||||||||||||||||||||||
| If \tcode{charT} is \tcode{char} and the ordinary literal encoding is UTF-8, | ||||||||||||||||||||||
| then let \tcode{msg} be \tcode{ec.message()} transcoded to UTF-8 | ||||||||||||||||||||||
| with maximal subparts of ill-formed subsequences substituted with \unicode{fffd}{replacement character} | ||||||||||||||||||||||
| per the Unicode Standard, Chapter 3.9 \unicode{fffd} Substi\-tution in Conversion. | ||||||||||||||||||||||
| \item | ||||||||||||||||||||||
| Otherwise, let \tcode{msg} be \tcode{ec.message()} | ||||||||||||||||||||||
| transcoded to an implementation-defined encoding. | ||||||||||||||||||||||
| \end{itemize} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \item | ||||||||||||||||||||||
| Otherwise, let \tcode{msg} be \tcode{std::format("{}:{}", ec.category().name(), ec.value())}. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \item | ||||||||||||||||||||||
| If the \tcode{?} option is used | ||||||||||||||||||||||
| then \tcode{msg} is formatted as an escaped string\iref{format.string.escaped}. | ||||||||||||||||||||||
| Writes \tcode{msg} into \tcode{ctx.out()}, adjusted according to the \fmtgrammarterm{error-code-format-spec}. | ||||||||||||||||||||||
|
Comment on lines
+1319
to
+1326
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This all seems to be a scription of Effects to me, not separate paragraphs, but maybe I'm missing something. The paper does put gaps here, but idk, this is weird.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we do have multi-paragraph \effects in some places, but having a separate numbered paragraph for every sentence is certainly non-optimal.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have an idea
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
| \end{itemize} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \pnum | ||||||||||||||||||||||
| \returns | ||||||||||||||||||||||
| An iterator past the end of the output range. | ||||||||||||||||||||||
| \end{itemdescr} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| \rSec2[syserr.errcondition]{Class \tcode{error_condition}} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||

Uh oh!
There was an error while loading. Please reload this page.