<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 698: system_error needs const char* constructors</title>
<meta property="og:title" content="Issue 698: system_error needs const char* constructors">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue698.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#CD1">CD1</a> status.</em></p>
<h3 id="698"><a href="lwg-defects.html#698">698</a>. <code>system_error</code> needs <code>const char*</code> constructors</h3>
<p><b>Section:</b> 19.5.8.1 <a href="https://wg21.link/syserr.syserr.overview">[syserr.syserr.overview]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2007-06-24 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In 19.5.8.1 <a href="https://wg21.link/syserr.syserr.overview">[syserr.syserr.overview]</a> we have the class definition of
<code>std::system_error</code>. In contrast to all exception classes, which
are constructible with a <code>what_arg string</code> (see 19.2 <a href="https://wg21.link/std.exceptions">[std.exceptions]</a>,
or <code>ios_base::failure</code> in  [ios::failure]), only overloads with with
<code>const string&amp;</code> are possible. For consistency with the re-designed
remaining exception classes this class should also provide
c'tors which accept a const <code>char* what_arg</code> string.
</p>
<p>
Please note that this proposed addition makes sense even
considering the given implementation hint for <code>what()</code>, because
<code>what_arg</code> is required to be set as <code>what_arg</code> of the base class
<code>runtime_error</code>, which now has the additional c'tor overload
accepting a <code>const char*</code>.
</p>


<p id="res-698"><b>Proposed resolution:</b></p>
<p>
This proposed wording assumes issue <a href="lwg-closed.html#832" title="Applying constexpr to System error support (Status: NAD)">832</a><sup><a href="https://cplusplus.github.io/LWG/issue832" title="Latest snapshot">(i)</a></sup> has been accepted and applied to the working paper.
</p>

<p>
Change 19.5.8.1 <a href="https://wg21.link/syserr.syserr.overview">[syserr.syserr.overview]</a> Class system_error overview, as indicated:
</p>

<blockquote><pre>
public:
  system_error(error_code ec, const string&amp; what_arg);
  <ins>system_error(error_code ec, const char* what_arg);</ins>
  system_error(error_code ec);
  system_error(int ev, const error_category* ecat,
      const string&amp; what_arg);
  <ins>system_error(int ev, const error_category* ecat,
      const char* what_arg);</ins>
  system_error(int ev, const error_category* ecat);
</pre></blockquote>

<p>
To 19.5.8.2 <a href="https://wg21.link/syserr.syserr.members">[syserr.syserr.members]</a> Class system_error members add:
</p>

<blockquote>
<pre>
system_error(error_code ec, const char* what_arg);
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of class <code>system_error</code>.
</p>
<p>
<i>Postconditions:</i> <code>code() == ec</code> and <code>strcmp(runtime_error::what(), what_arg) == 0</code>.
</p>
</blockquote>

<pre>
system_error(int ev, const error_category* ecat, const char* what_arg);
</pre>

<blockquote>
<p>
<i>Effects:</i> Constructs an object of class <code>system_error</code>.
</p>
<p>
<i>Postconditions:</i> <code>code() == error_code(ev, ecat)</code> and <code>strcmp(runtime_error::what(), what_arg) == 0</code>.
</p>
</blockquote>
</blockquote>






</body>
</html>
