equivalent("existing_thing", "not_existing_thing")
an error?Section: 31.12.13.13 [fs.op.equivalent] Status: C++20 Submitter: Billy Robert O'Neal III Opened: 2017-02-27 Last modified: 2021-02-25
Priority: 0
View all other issues in [fs.op.equivalent].
View all issues with C++20 status.
Discussion:
See discussion on the LWG mailing list with subject "Is equivalent("existing_thing", "not_existing_thing") an error?", abreviated below:
Billy O'Neal:The existing "an error is reported" effects say that an error is reported for
It's also unfortunate that the current spec requires reporting an error for!exists(p1) && !exists(p2)
, but I'm not sure that treatingequivalent("existing_thing", "not_existing_thing")
as "false
, no error" makes any more sense than forequivalent("not_existing_thing", "not_existing_thing")
.is_other(p1) && is_other(p2)
— there's no reason that you can't give a sane answer for paths to NT pipes. (Do POSIX FIFOs give garbage answers here?)
Davis Herring:
I'm fine with an error if either path does not exist. See also Late 29: I would much prefer
file_identity identity(const path&, bool resolve = true);which would of course produce an error if the path did not exist (or, with the default
See Late 30 and 32 (31 has been resolved). FIFOs pose no trouble: you can evenresolve
, was a broken symlink).fstat(2)
on the naked file descriptors produced bypipe(2)
. (That said, I observe the strange inconsistency that Linux but not macOS gives both ends of a pipe the samest_ino
.) POSIX has no reason that I know of to treat any file type specially forequivalent()
.
Billy O'Neal:
I think such a
file_identity
feature would be useful but we can always add it in addition toequivalent
post-C++17.
Beman Dawes:
Looks good to me. Maybe submit this as an issue right away in the hopes it can go in C++17?
[2017-03-04, Kona]
Set priority to 0; Tentatively Ready
Proposed resolution:
This wording is relative to N4640.
Make the following edits to 31.12.13.13 [fs.op.equivalent]:
bool equivalent(const path& p1, const path& p2); bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
-1- Lets1
ands2
befile_status
s determined as if bystatus(p1)
andstatus(p2)
, respectively.-2- Effects: Determines-3- Returns:s1
ands2
. If(!exists(s1) && !exists(s2)) || (is_other(s1) && is_other(s2))
an error is reported (27.10.7).true
, ifs1 == s2
andp1
andp2
resolve to the same file system entity, elsefalse
. The signature with argumentec
returnsfalse
if an error occurs. -4- Two paths are considered to resolve to the same file system entity if two candidate entities reside on the same device at the same location. [Note: On POSIX platforms, tThis is determined as if by the values of the POSIXstat
structure, obtained as if bystat()
for the two paths, having equalst_dev
values and equalst_ino
values. — end note] -?- Remarks:!exists(p1) || !exists(p2)
is an error. -5- Throws: As specified in 27.10.7.