system_category().default_error_condition(0)
is underspecifiedSection: 19.5.3.5 [syserr.errcat.objects] Status: C++23 Submitter: Jonathan Wakely Opened: 2021-09-23 Last modified: 2023-11-22
Priority: Not Prioritized
View all other issues in [syserr.errcat.objects].
View all issues with C++23 status.
Discussion:
19.5.3.5 [syserr.errcat.objects] says:
If the argument
ev
corresponds to a POSIXerrno
valueposv
, the function shall returnerror_condition(posv, generic_category())
. Otherwise, the function shall returnerror_condition(ev, system_category())
. What constitutes correspondence for any given operating system is unspecified.
What is "a POSIX errno
value"? Does it mean a value equal to one of the <cerrno>
Exxx
macros? Because in that case, the value 0
is not "a POSIX errno
value".
So arguably system_category().default_error_condition(0)
is required to return an
error_condition
using the "system" category, which means that error_code{} == error_condition{}
is required to be false
. This seems wrong.
0
should definitely correspond to the generic category.
Arguably that needs to be true
for all systems, because the std::error_code
API
strongly encourages a model where zero means "no error".
The proposed resolution has been implemented in libstdc++. Libc++ has always treated system error code
0
as corresponding to generic error code 0
.
[2021-10-14; Reflector poll]
Set status to Tentatively Ready after six votes in favour during reflector poll.
[2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP.]
Proposed resolution:
This wording is relative to N4892.
Modify 19.5.3.5 [syserr.errcat.objects] as indicated:
const error_category& system_category() noexcept;-3- Returns: […]
-4- Remarks: The object'sequivalent
virtual functions shall behave as specified for classerror_category
. The object'sname
virtual function shall return a pointer to the string"system"
. The object'sdefault_error_condition
virtual function shall behave as follows: If the argumentev
is equal to0
, the function returnserror_condition(0, generic_category())
. Otherwise, ifev
corresponds to a POSIXerrno
valueposv
, the functionshall returnreturnserror_condition(posv, generic_category())
. Otherwise, the functionshall returnreturnserror_condition(ev, system_category())
. What constitutes correspondence for any given operating system is unspecified. [Note 1: The number of potential system error codes is large and unbounded, and some might not correspond to any POSIXerrno
value. Thus implementations are given latitude in determining correspondence. — end note]