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.
filesystem::exists(const path&, error_code&)
error reportingSection: 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.
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
.
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.
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
-?- Effects: The signature with arguments
be afile_status
, determined as if bystatus(p)
orstatus(p, ec)
, respectively.ec
callsec.clear()
ifstatus_known(s)
. -2- Returns:exists(status(p))
orexists(status(p, ec))
, respectivelyexists(s)
.The signature with argument.ec
returnsfalse
if an error occurs