11<pre class='metadata'>
22Title : Fix encoding issues and add a formatter for std::error_code
33Shortname : P3395
4- Revision : 4
4+ Revision : 5
55Audience : LEWG
66Status : P
77Group : WG21
@@ -32,6 +32,14 @@ This paper proposes making `std::error_code` formattable using the formatting
3232facility introduced in C++20 (`std::format`) and fixes encoding issues in the
3333underlying API ([[LWG4156]] ).
3434
35+ Changes since R4 {#changes4}
36+ ================
37+
38+ - Fixed handling of `wchar_t` in the wording, making it consistent with the one
39+ from `std::filesystem::path`.
40+ - Clarify ABI implications of future changes.
41+ - Clarify why debug format applies to the whole error code.
42+
3543Changes since R3 {#changes3}
3644================
3745
@@ -130,18 +138,6 @@ generic :2
130138Additionally, it doesn’t allow formatting the error message and introduces
131139potential encoding issues, as the encoding of the category name is unspecified.
132140
133- A specifier for an error code’s value is intentionally not provided because it
134- is of limited use without the associated category information. Moreover, the
135- value can be easily accessed and formatted using other means, for example:
136-
137- ```c++
138- std::print("{}\n", ec.value());
139- ```
140-
141- This functionality is not currently provided by {fmt}, and over several years
142- of usage, there have been no requests to add it. However, if sufficient demand
143- emerges, it could be considered for future inclusion.
144-
145141Proposal {#proposal}
146142========
147143
@@ -284,6 +280,40 @@ compared to adopting a single encoding.
284280
285281<!-- ABI: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1196r0.html -->
286282
283+ A specifier for an error code’s value is intentionally not provided because it
284+ is of limited use without the associated category information. Moreover, the
285+ value can be easily accessed and formatted using other means, for example:
286+
287+ ```c++
288+ std::print("{}\n", ec.value());
289+ ```
290+
291+ This functionality is not currently provided by {fmt}, and over several years
292+ of usage, there have been no requests to add it. However, if sufficient demand
293+ emerges, it could be considered for future inclusion. Even if there are ABI
294+ implications to such extensions, since the current proposal is targeting C++29,
295+ there is plenty of time to do this.
296+
297+ The current proposal provides the debug format for `error_code`. The main
298+ for that is that the `:` separating the error category and code can be confused
299+ with `:` separating keys and values in a map. For example:
300+
301+ ```c++
302+ std::print("{}", std::map<std::error_code, int> {{std::error_code{}, 1}} );
303+ ```
304+ would be printed as
305+ ```
306+ {system:0: 1}
307+ ```
308+ without debug format and as
309+ ```
310+ {"system:0": 1}
311+ ```
312+ with.
313+
314+ This is also one of the reasons why the whole error code and not just error
315+ category should be quoted.
316+
287317Previous work {#previous}
288318=============
289319
@@ -305,8 +335,6 @@ template<class charT> struct formatter<error_code, charT>;
305335Add a new section "Formatting" [system.error.fmt] under "Class `error_code`"
306336[[syserr.errcode] (https://eel.is/c++draft/syserr.errcode)]:
307337
308- <!-- TODO: debug format -->
309-
310338<pre>
311339template<class charT> struct formatter<error_code, charT> {
312340 constexpr void set_debug_format();
@@ -353,10 +381,10 @@ where the productions <i>fill-and-align</i> and <i>width</i> are described in
353381
354382*Effects*: If the `s` option is used, then:
355383
356- - If the ordinary literal encoding is UTF-8, then let `msg` be `ec.message()`
357- transcoded to UTF-8 with maximal subparts of ill-formed subsequences
358- substituted with U+FFFD REPLACEMENT CHARACTER per the Unicode Standard,
359- Chapter 3.9 U+FFFD Substitution in Conversion.
384+ - If `charT` is `char` and the ordinary literal encoding is UTF-8, then let
385+ `msg` be `ec.message()` transcoded to UTF-8 with maximal subparts of
386+ ill-formed subsequences substituted with U+FFFD REPLACEMENT CHARACTER per
387+ the Unicode Standard, Chapter 3.9 U+FFFD Substitution in Conversion.
360388- Otherwise, let `msg` be `ec.message()` transcoded to an implementation-defined
361389 encoding.
362390
0 commit comments