<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3043: Bogus postcondition for filesystem_error constructor</title>
<meta property="og:title" content="Issue 3043: Bogus postcondition for filesystem_error constructor">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3043.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="3043"><a href="lwg-defects.html#3043">3043</a>. Bogus postcondition for <code>filesystem_error</code> constructor</h3>
<p><b>Section:</b> 31.12.7.2 <a href="https://wg21.link/fs.filesystem.error.members">[fs.filesystem.error.members]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2017-12-06 <b>Last modified:</b> 2021-06-06</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#fs.filesystem.error.members">issues</a> in [fs.filesystem.error.members].</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>
 [fs.filesystem_error.members] says that constructors of
<code>filesystem_error</code> have the postcondition that <code>runtime_error::what()</code> has the
value <code>what_arg.c_str()</code>. That's obviously incorrect: these are pointers
to distinct copies of the string in any sane implementation and cannot
possibly compare equal.
<p/>
The requirement seems suspect for a further reason: it mandates the content of the string
returned by <code>runtime_error::what()</code>, but <code>filesystem_error</code>
has no direct control over the construction of its indirect
non-virtual base class <code>runtime_error</code>. Instead, what is passed to <code>runtime_error</code>'s
constructor is determined by <code>system_error</code>'s constructor, which in many implementations
is an eagerly crafted error string. This is permitted by the specification of
<code>system_error</code> (see 19.5.8 <a href="https://wg21.link/syserr.syserr">[syserr.syserr]</a>) but would make the requirement unimplementable.
<p/>
The proposed wording below adjusts the postcondition using the formula of <code>system_error</code>'s
constructor. As an editorial change, it also replaces the postcondition tables with normal postcondition clauses,
in the spirit of <a href="https://github.com/cplusplus/draft/issues/1875">editorial issue 1875</a>.
</p>

<p><i>[
2018-01-12 Moved to Tentatively Ready after 5 positive votes on c++std-lib.
]</i></p>

<p><i>[2018-3-17 Adopted in Jacksonville]</i></p>



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

<ol>
<li><p>Replace  [fs.filesystem_error.members] p2-4, including Tables 119 through 121, with the following:</p>
<pre>
filesystem_error(const string&amp; what_arg, error_code ec);
</pre>
<blockquote>
-2- <i>Postconditions</i>: <code>code() == ec</code>, <code>path1().empty() == true</code>, <code>path2().empty() == true</code>,
and <code>string_view(what()).find(what_arg) != string_view::npos</code>.
</blockquote>
<pre>
filesystem_error(const string&amp; what_arg, const path&amp; p1, error_code ec);
</pre>
<blockquote>
-3- <i>Postconditions</i>: <code>code() == ec</code>, <code>path1()</code> returns a reference to the stored copy of <code>p1</code>, <code>path2().empty() == true</code>,
and <code>string_view(what()).find(what_arg) != string_view::npos</code>.
</blockquote>
<pre>
filesystem_error(const string&amp; what_arg, const path&amp; p1, const path&amp; p2, error_code ec);
</pre>
<blockquote>
-4- <i>Postconditions</i>: <code>code() == ec</code>, <code>path1()</code> returns a reference to the stored copy of <code>p1</code>,
<code>path2()</code> returns a reference to the stored copy of <code>p2</code>, and <code>string_view(what()).find(what_arg) != string_view::npos</code>.
</blockquote>
</li>
<li><p>Edit  [fs.filesystem_error.members] p7 as indicated:</p>
<pre>
const char* what() const noexcept override;
</pre>
<blockquote>
-7- <i>Returns</i>: <del>A string containing <code>runtime_error::what()</code>.</del><ins>An <span style="font-variant:small-caps">ntbs</span> that
incorporates the <code>what_arg</code> argument supplied to the constructor.</ins> The exact format is unspecified. Implementations should include
the <code>system_error::what()</code> string and the pathnames of <code>path1</code> and <code>path2</code> in the native format in the returned string.
</blockquote>
</li>
</ol>





</body>
</html>
