<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2937: Is equivalent("existing_thing", "not_existing_thing") an error?</title>
<meta property="og:title" content="Issue 2937: Is equivalent(&quot;existing_thing&quot;, &quot;not_existing_thing&quot;) an error?">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2937.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++20">C++20</a> status.</em></p>
<h3 id="2937"><a href="lwg-defects.html#2937">2937</a>. Is <code>equivalent("existing_thing", "not_existing_thing")</code> an error?</h3>
<p><b>Section:</b> 31.12.13.13 <a href="https://wg21.link/fs.op.equivalent">[fs.op.equivalent]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Billy Robert O'Neal III <b>Opened:</b> 2017-02-27 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#fs.op.equivalent">issues</a> in [fs.op.equivalent].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
See discussion on the LWG mailing list with subject "Is equivalent("existing_thing", "not_existing_thing") an error?", abreviated below:
<p/>
Billy O'Neal:
</p>
<blockquote>
<p>
The existing "an error is reported" effects say that an error is reported for <code>!exists(p1) &amp;&amp; !exists(p2)</code>, but 
I'm not sure that treating <code>equivalent("existing_thing", "not_existing_thing")</code> as "<code>false</code>, no error" makes any more 
sense than for <code>equivalent("not_existing_thing", "not_existing_thing")</code>.
<p/>
It's also unfortunate that the current spec requires reporting an error for <code>is_other(p1) &amp;&amp; is_other(p2)</code> &mdash; 
there's no reason that you can't give a sane answer for paths to NT pipes. (Do POSIX FIFOs give garbage answers here?)
</p>
</blockquote>
<p>
Davis Herring:
</p>
<blockquote>
<p>
I'm fine with an error if either path does not exist. See also Late 29: I would much prefer
</p>
<blockquote><pre>
file_identity identity(const path&amp;, bool resolve = true);
</pre></blockquote>
<p>
which would of course produce an error if the path did not exist (or, with the default <code>resolve</code>, was a broken symlink).
<p/>
See Late 30 and 32 (31 has been resolved). FIFOs pose no trouble: you can even <code>fstat(2)</code> on the naked file 
descriptors produced by <code>pipe(2)</code>. (That said, I observe the strange inconsistency that Linux but not macOS 
gives both ends of a pipe the same <code>st_ino</code>.)
<p/>
POSIX has no reason that I know of to treat any file type specially for <code>equivalent()</code>.
</p>
</blockquote>
<p>
Billy O'Neal:
</p>
<blockquote>
<p>
I think such a <code>file_identity</code> feature would be useful but we can always add it in addition to <code>equivalent</code> 
post-C++17.
</p>
</blockquote>
<p>
Beman Dawes:
</p>
<blockquote>
<p>
Looks good to me. Maybe submit this as an issue right away in the hopes it can go in C++17?
</p>
</blockquote>

<p><i>[2017-03-04, Kona]</i></p>

<p>Set priority to 0; Tentatively Ready</p>


<p id="res-2937"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4640">N4640</a>.</p>

<ol>
<li><p>Make the following edits to 31.12.13.13 <a href="https://wg21.link/fs.op.equivalent">[fs.op.equivalent]</a>:</p>

<blockquote>
<pre>
bool equivalent(const path&amp; p1, const path&amp; p2);
bool equivalent(const path&amp; p1, const path&amp; p2, error_code&amp; ec) noexcept;
</pre>
<blockquote>
<p>
<del>-1- Let <code>s1</code> and <code>s2</code> be <code>file_status</code>s determined as if by <code>status(p1)</code> and <code>status(p2)</code>, 
respectively.</del>
<p/>
<del>-2- <i>Effects:</i> Determines <code>s1</code> and <code>s2</code>. If <code>(!exists(s1) &amp;&amp; !exists(s2)) || (is_other(s1) &amp;&amp; 
is_other(s2))</code> an error is reported (27.10.7).</del>
<p/>
-3- <i>Returns:</i> <code>true</code>, if <del><code>s1 == s2</code> and</del> <code>p1</code> and <code>p2</code> resolve to the same file system 
entity, else <code>false</code>. The signature with argument <code>ec</code> returns <code>false</code> if an error occurs.
<p/>
-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. <ins>[<i>Note:</i> On POSIX platforms, t</ins><del>T</del>his is determined as if by the values 
of the POSIX <code>stat</code> structure, obtained as if by <code>stat()</code> for the two paths, having equal <code>st_dev</code> values and 
equal <code>st_ino</code> values. <ins>&mdash; <i>end note</i>]</ins>
<p/>
<ins>-?- <i>Remarks:</i> <code>!exists(p1) || !exists(p2)</code> is an error.</ins>
<p/>
-5- <i>Throws:</i> As specified in 27.10.7.
</p>
</blockquote>
</blockquote>

</li>
</ol>







</body>
</html>
