<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 471: result of what() implementation-defined</title>
<meta property="og:title" content="Issue 471: result of what() implementation-defined">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue471.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++11">C++11</a> status.</em></p>
<h3 id="471"><a href="lwg-defects.html#471">471</a>. result of <code>what()</code> implementation-defined</h3>
<p><b>Section:</b> 17.9.3 <a href="https://wg21.link/exception">[exception]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Martin Sebor <b>Opened:</b> 2004-06-28 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#exception">issues</a> in [exception].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>

<p>[lib.exception] specifies the following:</p>
<pre>
    exception (const exception&amp;) throw();
    exception&amp; operator= (const exception&amp;) throw();

    -4- Effects: Copies an exception object.
    -5- Notes: The effects of calling what() after assignment
        are implementation-defined.
</pre>

<p>
First, does the Note only apply to the assignment operator? If so,
what are the effects of calling what() on a copy of an object? Is
the returned pointer supposed to point to an identical copy of
the NTBS returned by what() called on the original object or not?
</p>

<p>
Second, is this Note intended to extend to all the derived classes
in section 19? I.e., does the standard provide any guarantee for
the effects of what() called on a copy of any of the derived class
described in section 19?
</p>

<p>
Finally, if the answer to the first question is no, I believe it
constitutes a defect since throwing an exception object typically
implies invoking the copy ctor on the object. If the answer is yes,
then I believe the standard ought to be clarified to spell out
exactly what the effects are on the copy (i.e., after the copy
ctor was called).
</p>

<p><i>[Redmond: Yes, this is fuzzy.  The issue of derived classes is
  fuzzy too.]</i></p>


<p><i>[
Batavia: Howard provided wording.
]</i></p>


<p><i>[
Bellevue:
]</i></p>


<blockquote>
<p>
Eric concerned this is unimplementable, due to nothrow guarantees.
Suggested implementation would involve reference counting.
</p>
<p>
Is the implied reference counting subtle enough to call out a note on
implementation? Probably not.
</p>
<p>
If reference counting required, could we tighten specification further
to require same pointer value? Probably an overspecification, especially
if exception classes defer evalutation of final string to calls to
what().
</p>
<p>
Remember issue moved open and not resolved at Batavia, but cannot
remember who objected to canvas a disenting opinion - please speak up if
you disagree while reading these minutes!
</p>
<p>
Move to Ready as we are accepting words unmodified.
</p>
</blockquote>

<p><i>[
Sophia Antipolis:
]</i></p>


<blockquote><p>
The issue was pulled from Ready.  It needs to make clear that only homogenous copying
is intended to be supported, not coping from a derived to a base.
</p></blockquote>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote>
<p>
Howard supplied the following replacement wording
for paragraph 7 of the proposed resolution:
</p>
<blockquote><p>
<ins>-7- <i>Postcondition:</i> <code>what()</code> shall return the same NTBS
  as would be obtained by using <code>static_cast</code>
  to cast the rhs to the same types as the lhs
  and then calling <code>what()</code> on that possibly sliced object.</ins>
</p></blockquote>
<p>
Pete asks what "the same NTBS" means.
</p>
</blockquote>

<p><i>[
2009-07-30 Niels adds:
]</i></p>


<blockquote><p>
Further discussion in the thread starting with c++std-lib-24512.
</p></blockquote>

<p><i>[
2009-09-24 Niels provided updated wording:
]</i></p>


<blockquote>
<p>
I think the resolution should at least guarantee
that the result of <code>what()</code> is independent of whether the compiler does
copy-elision. And for any class derived from <code>std::excepion</code> that has a
constructor that allows specifying a <code>what_arg</code>, it should make sure that
the text of a user-provided <code>what_arg</code> is preserved, when the object is
copied. Note that all the implementations I've tested already appear to
satisfy the proposed resolution, including MSVC 2008 SP1, Apache
stdcxx-4.2.1, GCC 4.1.2, GCC 4.3.2, and CodeGear C++ 6.13.
</p>
<p>
The proposed resolution was updated with help from Daniel Kr&uuml;gler;
the update aims to clarify that the proposed postcondition only
applies to homogeneous copying.
</p>
</blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Moved to Ready after inserting "publicly accessible" in two places.
</p></blockquote>



<p id="res-471"><b>Proposed resolution:</b></p>

<p>
Change 17.9.3 <a href="https://wg21.link/exception">[exception]</a> to:
</p>

<blockquote>
<p>
-1- The class <code>exception</code> defines the base class for the types of
objects thrown as exceptions by C++ standard library components, and
certain expressions, to report errors detected during program execution.
</p>
<p><ins>
Each standard library class <code>T</code> that derives from class
<code>exception</code> shall have a publicly accessible copy constructor and a publicly accessible copy assignment
operator that do not exit with an exception. These member functions
shall preserve the following postcondition: If two objects <i>lhs</i>
and <i>rhs</i> both have dynamic type <code>T</code>, and <i>lhs</i> is a
copy of <i>rhs</i>, then <code>strcmp(<i>lhs</i>.what(),
<i>rhs</i>.what()) == 0</code>.
</ins></p>
<p>
 ...
</p>

<pre>exception(const exception&amp; <ins>rhs</ins>) throw();
exception&amp; operator=(const exception&amp; <ins>rhs</ins>) throw();</pre>

<blockquote>
<p>
-4- <i>Effects:</i> Copies an exception object.
</p>
<p>
<del> -5- <i>Remarks:</i> The effects of calling <code>what()</code> after assignment
are implementation-defined.</del>
</p>
<p>
<ins>-5- <i>Postcondition:</i>
	If <code>*this</code>
	and <i>rhs</i> both have dynamic type <code>exception</code>
	then <code>strcmp(what(), <i>rhs</i>.what()) == 0</code>.</ins>
</p>

</blockquote>

</blockquote>





</body>
</html>
