<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3244: Constraints for Source in &sect;[fs.path.req] insufficiently constrainty</title>
<meta property="og:title" content="Issue 3244: Constraints for Source in &sect;[fs.path.req] insufficiently constrainty">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3244.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="3244"><a href="lwg-defects.html#3244">3244</a>. Constraints for <code>Source</code> in &sect;[fs.path.req] insufficiently constrainty</h3>
<p><b>Section:</b> 31.12.6.4 <a href="https://wg21.link/fs.path.req">[fs.path.req]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2019-08-02 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</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>
<code>std::filesystem::path</code> has a number of functions - notably including a conversion
constructor template (31.12.6.5.1 <a href="https://wg21.link/fs.path.construct">[fs.path.construct]</a>) and assignment operator template
(31.12.6.5.2 <a href="https://wg21.link/fs.path.assign">[fs.path.assign]</a>) - that accept <code>const Source&amp;</code>. Per
31.12.6.4 <a href="https://wg21.link/fs.path.req">[fs.path.req]</a> paragraph 2:
</p><blockquote><p>
-2- Functions taking template parameters named <code>Source</code> shall not participate in overload
resolution unless either
</p><p>
(2.1) &mdash; <code>Source</code> is a specialization of <code>basic_string</code> or
<code>basic_string_view</code>, or
</p><p>
(2.2) &mdash; the <i>qualified-id</i>
<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.
</p></blockquote><p>
<code>iterator_traits&lt;decay_t&lt;path&gt;&gt;::value_type</code> is not valid in C++17, so this
specification was sufficient to guard against the conversion constructor template (respectively
assignment operator template) "pretending" to be copy constructor (respectively copy assignment
operator). <a href="https://wg21.link/p0896r4">P0896R4 "The One Ranges Proposal"</a>, however,
altered the definition of <code>iterator_traits</code> in the working draft. It now has some convenient
default behaviors for types that meet (roughly) the syntax of the <i><code>Cpp17InputIterator</code></i>
requirements. Notably those requirements include copy construction and copy assignment.
</p><p>
In the working draft, to determine the copyability of <code>std::filesystem::path</code> we must perform
overload resolution to determine if we can initialize a <code>path</code> from a constant lvalue of type
<code>path</code>. The conversion constructor template that accepts <code>const Source&amp;</code> is a
candidate, since its second argument is defaulted, so
we must perform template argument deduction to see if this constructor is viable. <code>Source</code> is
deduced to <code>path</code> and we then must check the constraint from 31.12.6.4 <a href="https://wg21.link/fs.path.req">[fs.path.req]</a>
paragraph 2.2 (above). Checking the constraint requires us to specialize
<code>iterator_traits&lt;path&gt;</code>, which (per 24.3.2.3 <a href="https://wg21.link/iterator.traits">[iterator.traits]</a> paragraph 3.2)
requires us to determine if <code>path</code> satisfies the exposition-only
<i><code>cpp17-input-iterator</code></i> concept, which requires <code>path</code> to be copyable.
</p><p>
We've completed a cycle: determining if <code>path</code> is copyable requires us to first determine if
<code>path</code> is copyable. This unfortunate constraint recursion can be broken by explicitly
specifying that <code>path</code> is not a valid <code>Source</code>.
</p>

<p><i>[2019-08-17 Issue Prioritization]</i></p>

<p>Status to Tentatively Ready and priority to 0 after seven positive votes on the reflector.</p>


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

<ol>
<li><p>Modify 31.12.6.4 <a href="https://wg21.link/fs.path.req">[fs.path.req]</a> as indicated:</p>
<blockquote><p>
-2- Functions taking template parameters named <code>Source</code> shall not participate in overload
resolution unless <ins><code>Source</code> denotes a type other than <code>path</code>, and</ins> either
</p><p>
[&hellip;]
</p></blockquote>
</li>
</ol>





</body>
</html>
