<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2176: Special members for wstring_convert and wbuffer_convert</title>
<meta property="og:title" content="Issue 2176: Special members for wstring_convert and wbuffer_convert">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2176.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++14">C++14</a> status.</em></p>
<h3 id="2176"><a href="lwg-defects.html#2176">2176</a>. Special members for <code>wstring_convert</code> and <code>wbuffer_convert</code></h3>
<p><b>Section:</b> 99 [depr.conversions.string], 99 [depr.conversions.buffer] <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2012-08-02 <b>Last modified:</b> 2017-09-07</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#depr.conversions.string">active issues</a> in [depr.conversions.string].</p>
<p><b>View all other</b> <a href="lwg-index.html#depr.conversions.string">issues</a> in [depr.conversions.string].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>

<p>
See discussion following <a href="http://listarchives.isocpp.org/cgi-bin/wg21/message?wg=lib&amp;msg=32699">c++std-lib-32699</a>.
<p/>
The constructors for <code>wstring_convert</code> and <code>wbuffer_convert</code> should be explicit, to avoid 
implicit conversions which take ownership of a <code>Codecvt</code> pointer and delete it unexpectedly.
<p/>
Secondly,  [conversions.buffer] p11 describes a destructor which is not declared in the class 
synopsis in p2.
<p/>
Finally, and most importantly, the definitions in  [conversions.string] and 
 [conversions.buffer] imply implicitly-defined copy constructors and assignment operators, which 
would do shallow copies of the owned <code>Codecvt</code> objects and result in undefined behaviour in the 
destructors.
<p/>
<code>Codecvt</code> is not required to be <code>CopyConstructible</code>, so deep copies are not possible.  
The <code>wstring_convert</code> and <code>wstring_buffer</code> types could be made move-only, but the proposed 
resolution below doesn't do so because of the lack of preconditions regarding null <code>Codecvt</code> pointers
and the absence of observer functions that would allow users to check preconditions (see also LWG <a href="lwg-defects.html#2175" title="wstring_convert and wbuffer_convert validity (Status: C++14)">2175</a><sup><a href="https://cplusplus.github.io/LWG/issue2175" title="Latest snapshot">(i)</a></sup>).
</p>

<p><i>[2013-03-15 Issues Teleconference]</i></p>

<p>
Moved to Review.
</p>
<p>
Jonathan pointed out that you can have an implicit constructor that takes ownership of a heap reference,
which would result an unexpected deletion.
</p>
<p>
No-one really likes the 'naked new' in the interface here, either.
</p>

<p><i>[2013-04-18, Bristol]</i></p>




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

<ol>
<li><p>Edit the class template <code>wstring_convert</code> synopsis in  [conversions.string] p2:</p>

<blockquote><pre>
<ins>explicit</ins> wstring_convert(Codecvt *pcvt = new Codecvt);
wstring_convert(Codecvt *pcvt, state_type state);
<ins>explicit</ins> wstring_convert(const byte_string&amp; byte_err,
                         const wide_string&amp; wide_err = wide_string());
~wstring_convert();
<ins>
wstring_convert(const wstring_convert&amp;) = delete;
wstring_convert&amp; operator=(const wstring_convert&amp;) = delete;
</ins>				 
</pre></blockquote>
</li>

<li><p>Edit the signatures before  [conversions.string] p16:</p>

<blockquote><pre>
<ins>explicit</ins> wstring_convert(Codecvt *pcvt = new Codecvt);
wstring_convert(Codecvt *pcvt, state_type state);
<ins>explicit</ins> wstring_convert(const byte_string&amp; byte_err,
    const wide_string&amp; wide_err = wide_string());
</pre></blockquote>
</li>

<li><p>Edit the class template <code>wbuffer_convert</code> synopsis in  [conversions.buffer] p2:</p>

<blockquote><pre>
<ins>explicit</ins> wbuffer_convert(std::streambuf *bytebuf = 0,
                         Codecvt *pcvt = new Codecvt,
                         state_type state = state_type());
<ins>
~wbuffer_convert();

wbuffer_convert(const wbuffer_convert&amp;) = delete;
wbuffer_convert&amp; operator=(const wbuffer_convert&amp;) = delete;
</ins>						 
</pre></blockquote>
</li>

<li><p>Edit the signature before  [conversions.buffer] p10:</p>

<blockquote><pre>
<ins>explicit</ins> wbuffer_convert(std::streambuf *bytebuf = 0,
    Codecvt *pcvt = new Codecvt, state_type state = state_type());
</pre></blockquote>
</li>

</ol>





</body>
</html>
