This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++23 status.

3598. system_category().default_error_condition(0) is underspecified

Section: 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 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.

[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.

  1. Modify 19.5.3.5 [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]