Title
system_category().default_error_condition(0) is underspecified
Status
c++23
Section
[syserr.errcat.objects]
Submitter
Jonathan Wakely

Created on 2021-09-23.00:00:00 last changed 12 months ago

Messages

Date: 2022-02-10.12:58:57

Proposed resolution:

This wording is relative to N4892.

  1. Modify [syserr.errcat.objects] as indicated:

    const error_category& system_category() noexcept;
    

    -3- Returns: […]

    -4- Remarks: The object's equivalent virtual functions shall behave as specified for class error_category. The object's name virtual function shall return a pointer to the string "system". The object's default_error_condition virtual function shall behave as follows:

    If the argument ev is equal to 0, the function returns error_condition(0, generic_category()). Otherwise, if ev corresponds to a POSIX errno value posv, the function shall returnreturns error_condition(posv, generic_category()). Otherwise, the function shall returnreturns error_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 POSIX errno value. Thus implementations are given latitude in determining correspondence. — end note]

Date: 2022-02-10.00:00:00

[ 2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP. ]

Date: 2021-10-15.00:00:00

[ 2021-10-14; Reflector poll ]

Set status to Tentatively Ready after six votes in favour during reflector poll.

Date: 2021-09-23.00:00:00

[syserr.errcat.objects] says:

If the argument ev corresponds to a POSIX errno value posv, the function shall return error_condition(posv, generic_category()). Otherwise, the function shall return error_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.

For POSIX-based systems the value 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.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-02-10 12:58:57adminsetmessages: + msg12348
2022-02-10 12:58:57adminsetstatus: ready -> wp
2021-10-14 11:35:22adminsetmessages: + msg12147
2021-10-14 11:35:22adminsetstatus: new -> ready
2021-09-24 15:29:33adminsetmessages: + msg12063
2021-09-23 00:00:00admincreate