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

2725. filesystem::exists(const path&, error_code&) error reporting

Section: 31.12.13.14 [fs.op.exists] Status: C++17 Submitter: Jonathan Wakely Opened: 2016-06-06 Last modified: 2017-07-30

Priority: 1

View all issues with C++17 status.

Discussion:

The filesystem::exists(const path&) function does not throw an exception if the file doesn't exist, but the corresponding function taking an error_code& argument does set it to indicate an error.

It seems sensible for filesystem::exists(const path&, error_code&) to call ec.clear() if status(p, ec).type() == file_type::not_found.

[2016-06, Oulu — Jonathan comments and provides wording]

The sentence "The signature with argument ec returns false if an error occurs." means that given a file such that status(p).type() == file_type::unknown, exists(p) is true but exists(p, ec) is false.

I believe we should make the behaviour of exists(p) and exists(p, ec) consistent, so that the latter clears ec except when the former would throw an exception, which is only for the file_type::none case.

[2016-06, Oulu]

Prioritized as P1

Voted to Ready 7-0 Tuesday evening in Oulu

Proposed resolution:

This wording is relative to N4594.

  1. Insert a new paragraph before 31.12.13.14 [fs.op.exists] p2 and edit it as shown:

    bool exists(const path& p);
    bool exists(const path& p, error_code& ec) noexcept;
    

    -?- Let s be a file_status, determined as if by status(p) or status(p, ec), respectively.

    -?- Effects: The signature with argument ec calls ec.clear() if status_known(s).

    -2- Returns: exists(status(p)) or exists(status(p, ec)), respectivelyexists(s). The signature with argument ec returns false if an error occurs.