<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2711: path is convertible from approximately everything under the sun</title>
<meta property="og:title" content="Issue 2711: path is convertible from approximately everything under the sun">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2711.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++17">C++17</a> status.</em></p>
<h3 id="2711"><a href="lwg-defects.html#2711">2711</a>. <code>path</code> is convertible from approximately everything under the sun</h3>
<p><b>Section:</b> 31.12.6.5.1 <a href="https://wg21.link/fs.path.construct">[fs.path.construct]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2016-05-10 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>1
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The unconstrained <code>template&lt;class Source&gt; path(const Source&amp; source);</code> constructor defines an 
implicit conversion from pretty much everything to <code>path</code>. This can lead to surprising ambiguities in 
overload resolution.
<p/>
For example, given LWG <a href="lwg-defects.html#2676" title="Provide filesystem::path overloads for File-based streams (Status: C++17)">2676</a><sup><a href="https://cplusplus.github.io/LWG/issue2676" title="Latest snapshot">(i)</a></sup>'s proposed resolution, the following code appears to be ambiguous:
</p>
<blockquote><pre>
struct meow {
  operator const char *() const;
};

std::ifstream purr(meow{});
</pre></blockquote>
<p>
because a <code>meow</code> can be converted to either a <code>path</code> or a <code>const char*</code> by a user-defined 
conversion, even though part of the stated goal of LWG <a href="lwg-defects.html#2676" title="Provide filesystem::path overloads for File-based streams (Status: C++17)">2676</a><sup><a href="https://cplusplus.github.io/LWG/issue2676" title="Latest snapshot">(i)</a></sup>'s P/R is to avoid "break[ing] user 
code depending on user-defined automatic conversions to the existing argument types".
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to N4582.
</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> <code>decay_t&lt;Source&gt;</code> handles both the input iterator case (31.12.6.4 <a href="https://wg21.link/fs.path.req">[fs.path.req]</a>/1.2) and 
the array case (31.12.6.4 <a href="https://wg21.link/fs.path.req">[fs.path.req]</a>/1.3). The level of constraints required is debatable; the following wording limits 
the constraint to "is a <code>basic_string</code> or an iterator", but perhaps stronger constraints (e.g., an 
<code>iterator_category</code> check in the second case, and/or a <code>value_type</code> check for both cases) would be desirable.]
</p>
</blockquote>

<ol>
<li><p>Change 31.12.6.5.1 <a href="https://wg21.link/fs.path.construct">[fs.path.construct]</a> as indicated:</p>

<blockquote>
<pre>
template &lt;class Source&gt;
  path(const Source&amp; source);
template &lt;class InputIterator&gt;
  path(InputIterator first, InputIterator last);
</pre>
<blockquote>
<p>
-4- <i>Effects:</i> Constructs an object of class <code>path</code>, storing the effective range of <code>source</code> (27.10.8.3) 
or the range <code>[first, last)</code> in <code>pathname</code>, converting format and encoding if required (27.10.8.2.1).
<p/>
<ins>-?- <i>Remarks:</i> The first overload shall not participate in overload resolution unless either <code>Source</code> 
is a specialization of <code>basic_string</code> or the qualified-id <code>iterator_traits&lt;decay_t&lt;Source&gt;&gt;::value_type</code> 
is valid and denotes a type (13.10.3 <a href="https://wg21.link/temp.deduct">[temp.deduct]</a>).</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2016-05-28, Eric Fiselier comments suggests alternative wording]</i></p>

<p>
Functions taking <code>EcharT</code> or <code>Source</code> parameter types often provide additional overloads with the 
same arity and concrete types. In order to allow conversions to these concrete types in the interface we need to 
explicitly disable the <code>EcharT</code> and <code>Source</code> overloads.
</p>

<p><i>[2016-06-19, Eric and Tim improve the wording]</i></p>


<p><i>[2016-06, Oulu]</i></p>

<p>Voted to Ready 8-0 Monday morning in Oulu</p>


<p id="res-2711"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N4594.
</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> Functions taking <code>EcharT</code> or <code>Source</code> parameter types often provide additional overloads with the 
same arity and concrete types. In order to allow conversions to these concrete types in the interface we need to explicitly disable 
the <code>EcharT</code> and <code>Source</code> overloads.]
</p>
</blockquote>

<ol>
<li><p>Change 31.12.3 <a href="https://wg21.link/fs.req">[fs.req]</a> as indicated:</p>

<blockquote>
<p>
-2- <del>Template parameters named <code>EcharT</code> shall be</del><ins>Functions with template parameters named 
<code>EcharT</code> shall not participate in overload resolution unless <code>EcharT</code> is</ins> one of the encoded 
character types.
</p>
</blockquote>
</li>

<li><p>Insert a new paragraph between 31.12.6.4 <a href="https://wg21.link/fs.path.req">[fs.path.req]</a> p1 and p2 as indicated:</p>

<blockquote>
<p>
<ins>-?- Functions taking template parameters named <code>Source</code> shall not participate in overload resolution unless either 
<code>Source</code> is a specialization of <code>basic_string</code> or the qualified-id <code>iterator_traits&lt;decay_t&lt;Source&gt;&gt;::value_type</code> 
is valid and denotes a possibly <code>const</code> encoded character type (13.10.3 <a href="https://wg21.link/temp.deduct">[temp.deduct]</a>).</ins> 
</p>
</blockquote>
</li>
</ol>





</body>
</html>
