<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3065: LWG 2989 missed that all path's other operators should be hidden friends as well</title>
<meta property="og:title" content="Issue 3065: LWG 2989 missed that all path's other operators should be hidden friends as well">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3065.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="3065"><a href="lwg-defects.html#3065">3065</a>. LWG 2989 missed that all <code>path</code>'s other operators should be hidden friends as well</h3>
<p><b>Section:</b> 31.12.6.8 <a href="https://wg21.link/fs.path.nonmember">[fs.path.nonmember]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Billy O'Neal III <b>Opened:</b> 2018-02-13 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>2
</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>
Consider the following program:
</p>
<blockquote><pre>
// <a href="https://godbolt.org/g/2wwqe8">See godbolt link</a>
#include &lt;assert.h&gt;
#include &lt;string&gt;
#include &lt;filesystem&gt;

using namespace std;
using namespace std::filesystem;

int main() {
  bool b = L"a//b" == std::string("a/b");
  assert(b); // passes. What?!
  return b;
}
</pre></blockquote>
<p>
<code>L"a"</code> gets converted into a <code>path</code>, and the string gets converted into a <code>path</code>, 
and then those paths are compared for equality. But <code>path</code> equality comparison doesn't work 
anything like string equality comparison, leading to surprises.
<p/>
<code>path</code>'s other operators should be made hidden friends as well, so that one side or the other 
of a given operator is of type <code>path</code> before those conversions apply.
</p>

<p><i>[2018-02-20, Priority set to 2 after mailing list discussion]</i></p>


<p><i>[2018-08-23 Batavia Issues processing]</i></p>

<p>Status to Tentatively Ready</p>
<p><i>[2018-11, Adopted in San Diego]</i></p>



<p id="res-3065"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4713">N4713</a>.
<p/>
All drafting notes from LWG <a href="lwg-defects.html#2989" title="path's stream insertion operator lets you insert everything under the sun (Status: C++20)">2989</a><sup><a href="https://cplusplus.github.io/LWG/issue2989" title="Latest snapshot">(i)</a></sup> apply here too.
</p>

<ol>
<li><p>Modify 31.12.4 <a href="https://wg21.link/fs.filesystem.syn">[fs.filesystem.syn]</a>, header <code>&lt;filesystem&gt;</code> synopsis, as indicated:</p>

<blockquote>
<pre>
[&hellip;]
<i>// 31.12.6.8 <a href="https://wg21.link/fs.path.nonmember">[fs.path.nonmember]</a>, path non-member functions</i>
void swap(path&amp; lhs, path&amp; rhs) noexcept;
size_t hash_value(const path&amp; p) noexcept;

<del>bool operator==(const path&amp; lhs, const path&amp; rhs) noexcept;
bool operator!=(const path&amp; lhs, const path&amp; rhs) noexcept;
bool operator&lt; (const path&amp; lhs, const path&amp; rhs) noexcept;
bool operator&lt;=(const path&amp; lhs, const path&amp; rhs) noexcept;
bool operator&gt; (const path&amp; lhs, const path&amp; rhs) noexcept;
bool operator&gt;=(const path&amp; lhs, const path&amp; rhs) noexcept;

path operator/ (const path&amp; lhs, const path&amp; rhs);</del>
[&hellip;]
</pre>
</blockquote>
</li>

<li><p>Modify 31.12.6.8 <a href="https://wg21.link/fs.path.nonmember">[fs.path.nonmember]</a> as indicated:</p>

<blockquote>
<pre>
[&hellip;]
<ins>friend</ins> bool operator&lt; (const path&amp; lhs, const path&amp; rhs) noexcept;
[&hellip;]
<ins>friend</ins> bool operator&lt;=(const path&amp; lhs, const path&amp; rhs) noexcept;
[&hellip;]
<ins>friend</ins> bool operator&gt; (const path&amp; lhs, const path&amp; rhs) noexcept;
[&hellip;]
<ins>friend</ins> bool operator&gt;=(const path&amp; lhs, const path&amp; rhs) noexcept;
[&hellip;]
<ins>friend</ins> bool operator==(const path&amp; lhs, const path&amp; rhs) noexcept;
[&hellip;]
<ins>friend</ins> bool operator!=(const path&amp; lhs, const path&amp; rhs) noexcept;
[&hellip;]
<ins>friend</ins> path operator/ (const path&amp; lhs, const path&amp; rhs);
[&hellip;]
</pre>
</blockquote>
</li>

<li><p>Modify 31.12.6 <a href="https://wg21.link/fs.class.path">[fs.class.path]</a>, class <code>path</code> synopsis, as indicated:</p>

<blockquote>
<pre>
class path {
public:
  [&hellip;]
  <i>// 31.12.6.5.5 <a href="https://wg21.link/fs.path.modifiers">[fs.path.modifiers]</a>, modifiers</i>
  [&hellip;]
  
  <ins><i>// 31.12.6.8 <a href="https://wg21.link/fs.path.nonmember">[fs.path.nonmember]</a>, non-member operators</i></ins>
  <ins>friend bool operator&lt; (const path&amp; lhs, const path&amp; rhs) noexcept;</ins>
  <ins>friend bool operator&lt;=(const path&amp; lhs, const path&amp; rhs) noexcept;</ins>
  <ins>friend bool operator&gt; (const path&amp; lhs, const path&amp; rhs) noexcept;</ins>
  <ins>friend bool operator&gt;=(const path&amp; lhs, const path&amp; rhs) noexcept;</ins>
  <ins>friend bool operator==(const path&amp; lhs, const path&amp; rhs) noexcept;</ins>
  <ins>friend bool operator!=(const path&amp; lhs, const path&amp; rhs) noexcept;</ins>
  
  <ins>friend path operator/ (const path&amp; lhs, const path&amp; rhs);</ins>
  
  <i>// 31.12.6.5.6 <a href="https://wg21.link/fs.path.native.obs">[fs.path.native.obs]</a>, native format observers</i>
  [&hellip;]
};
</pre>
</blockquote>
</li>
</ol>






</body>
</html>
