<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 767: Forwarding and backward compatibility</title>
<meta property="og:title" content="Issue 767: Forwarding and backward compatibility">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue767.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#Resolved">Resolved</a> status.</em></p>
<h3 id="767"><a href="lwg-defects.html#767">767</a>. Forwarding and backward compatibility</h3>
<p><b>Section:</b> 23 <a href="https://wg21.link/containers">[containers]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Sylvain Pion <b>Opened:</b> 2007-12-28 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#containers">active issues</a> in [containers].</p>
<p><b>View all other</b> <a href="lwg-index.html#containers">issues</a> in [containers].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Playing with g++'s C++0X mode, I noticed that the following code, which used to compile:
</p>

<blockquote><pre>
#include &lt;vector&gt;

int main()
{
    std::vector&lt;char *&gt; v;
    v.push_back(0);
}
</pre></blockquote>

<p>
now fails with the following error message:
</p>

<blockquote><p>
.../include/c++/4.3.0/ext/new_allocator.h: In member function 'void __gnu_cxx::new_allocator&lt;_Tp&gt;::construct(_Tp*, _Args&amp;&amp; ...) [with _Args = int, _Tp = char*]':
.../include/c++/4.3.0/bits/stl_vector.h:707:   instantiated from 'void std::vector&lt;_Tp, _Alloc&gt;::push_back(_Args&amp;&amp; ...) [with _Args = int, _Tp = char*, _Alloc = std::allocator&lt;char*&gt;]'
test.cpp:6:   instantiated from here
.../include/c++/4.3.0/ext/new_allocator.h:114: error: invalid conversion from 'int' to 'char*'
</p></blockquote>

<p>
As far as I know, g++ follows the current draft here.
</p>
<p>
Does the committee really intend to break compatibility for such cases?
</p>

<p><i>[
Sylvain adds: 
]</i></p>


<blockquote>
<p>
I just noticed that <code>std::pair</code> has the same issue.
The following now fails with GCC's -std=c++0x mode:
</p>

<blockquote><pre>
#include &lt;utility&gt;

int main()
{
   std::pair&lt;char *, char *&gt; p (0,0);
}
</pre></blockquote>

<p>
I have not made any general audit for such problems elsewhere.
</p>
</blockquote>

<p><i>[
Related to <a href="lwg-defects.html#756" title="Container adaptors push (Status: Resolved)">756</a><sup><a href="https://cplusplus.github.io/LWG/issue756" title="Latest snapshot">(i)</a></sup>
]</i></p>


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


<blockquote>
<p>
Motivation is to handle the old-style int-zero-valued <code>NULL</code> pointers.
Problem: this solution requires concepts in some cases, which some users
will be slow to adopt. Some discussion of alternatives involving
prohibiting variadic forms and additional library-implementation
complexity.
</p>
<p>
Discussion of "perfect world" solutions, the only such solution put
forward being to retroactively prohibit use of the integer zero for a
<code>NULL</code> pointer. This approach was deemed unacceptable given the large
bodies of pre-existing code that do use integer zero for a <code>NULL</code> pointer.
</p>
<p>
Another approach is to change the member names. Yet another approach is
to forbid the extension in absence of concepts.
</p>
<p>
Resolution: These issues (<a href="lwg-defects.html#756" title="Container adaptors push (Status: Resolved)">756</a><sup><a href="https://cplusplus.github.io/LWG/issue756" title="Latest snapshot">(i)</a></sup>, <a href="lwg-defects.html#767" title="Forwarding and backward compatibility (Status: Resolved)">767</a><sup><a href="https://cplusplus.github.io/LWG/issue767" title="Latest snapshot">(i)</a></sup>, <a href="lwg-closed.html#760" title="The emplace issue (Status: NAD)">760</a><sup><a href="https://cplusplus.github.io/LWG/issue760" title="Latest snapshot">(i)</a></sup>, 
<a href="lwg-closed.html#763" title="Renaming emplace() overloads (Status: NAD)">763</a><sup><a href="https://cplusplus.github.io/LWG/issue763" title="Latest snapshot">(i)</a></sup>) will be subsumed into a paper to be produced by Alan Talbot 
in time for review at the 2008 meeting in France. Once this paper is produced, 
these issues will be moved to <del>NAD</del><ins>Resolved</ins>.
</p>
</blockquote>



<p id="res-767"><b>Proposed resolution:</b></p>
<p>
Add the following rows to Table 90 "Optional sequence container operations", 23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a>:
</p>

<blockquote>
<table border="1">
<tr>
<th>expression</th> <th>return type</th> <th>assertion/note<br/>pre-/post-condition</th> <th>container</th>
</tr>

<tr>
<td>
<code>a.push_front(t)</code>
</td>
<td>
<code>void</code>
</td>
<td>
<code>a.insert(a.begin(), t)</code><br/>
<i>Requires:</i> <code>T</code> shall be <code>CopyConstructible</code>.
</td>
<td>
<code>list, deque</code>
</td>
</tr>

<tr>
<td>
<code>a.push_front(rv)</code>
</td>
<td>
<code>void</code>
</td>
<td>
<code>a.insert(a.begin(), rv)</code><br/>
<i>Requires:</i> <code>T</code> shall be <code>MoveConstructible</code>.
</td>
<td>
<code>list, deque</code>
</td>
</tr>

<tr>
<td>
<code>a.push_back(t)</code>
</td>
<td>
<code>void</code>
</td>
<td>
<code>a.insert(a.end(), t)</code><br/>
<i>Requires:</i> <code>T</code> shall be <code>CopyConstructible</code>.
</td>
<td>
<code>list, deque, vector, basic_string</code>
</td>
</tr>

<tr>
<td>
<code>a.push_back(rv)</code>
</td>
<td>
<code>void</code>
</td>
<td>
<code>a.insert(a.end(), rv)</code><br/>
<i>Requires:</i> <code>T</code> shall be <code>MoveConstructible</code>.
</td>
<td>
<code>list, deque, vector, basic_string</code>
</td>
</tr>

</table>
</blockquote>

<p>
Change the synopsis in 23.3.5 <a href="https://wg21.link/deque">[deque]</a>:
</p>

<blockquote><pre>
<ins>void push_front(const T&amp; x);</ins>
<ins>void push_front(T&amp;&amp; x);</ins>
<ins>void push_back(const T&amp; x);</ins>
<ins>void push_back(T&amp;&amp; x);</ins>
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_front(Args&amp;&amp;... args);
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_back(Args&amp;&amp;... args);
</pre></blockquote>

<p>
Change 23.3.5.4 <a href="https://wg21.link/deque.modifiers">[deque.modifiers]</a>:
</p>

<blockquote><pre>
<ins>void push_front(const T&amp; x);</ins>
<ins>void push_front(T&amp;&amp; x);</ins>
<ins>void push_back(const T&amp; x);</ins>
<ins>void push_back(T&amp;&amp; x);</ins>
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_front(Args&amp;&amp;... args);
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_back(Args&amp;&amp;... args);
</pre></blockquote>

<p>
Change the synopsis in 23.3.11 <a href="https://wg21.link/list">[list]</a>:
</p>

<blockquote><pre>
<ins>void push_front(const T&amp; x);</ins>
<ins>void push_front(T&amp;&amp; x);</ins>
<ins>void push_back(const T&amp; x);</ins>
<ins>void push_back(T&amp;&amp; x);</ins>
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_front(Args&amp;&amp;... args);
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_back(Args&amp;&amp;... args);
</pre></blockquote>

<p>
Change 23.3.11.4 <a href="https://wg21.link/list.modifiers">[list.modifiers]</a>:
</p>

<blockquote><pre>
<ins>void push_front(const T&amp; x);</ins>
<ins>void push_front(T&amp;&amp; x);</ins>
<ins>void push_back(const T&amp; x);</ins>
<ins>void push_back(T&amp;&amp; x);</ins>
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_front(Args&amp;&amp;... args);
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_back(Args&amp;&amp;... args);
</pre></blockquote>

<p>
Change the synopsis in 23.3.13 <a href="https://wg21.link/vector">[vector]</a>:
</p>

<blockquote><pre>
<ins>void push_back(const T&amp; x);</ins>
<ins>void push_back(T&amp;&amp; x);</ins>
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_back(Args&amp;&amp;... args);
</pre></blockquote>

<p>
Change 23.3.13.5 <a href="https://wg21.link/vector.modifiers">[vector.modifiers]</a>:
</p>

<blockquote><pre>
<ins>void push_back(const T&amp; x);</ins>
<ins>void push_back(T&amp;&amp; x);</ins>
template &lt;class... Args&gt; <ins>requires Constructible&lt;T, Args&amp;&amp;...&gt;</ins> void push_back(Args&amp;&amp;... args);
</pre></blockquote>




<p><b>Rationale:</b></p>
<p>
Addressed by
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2680.pdf">N2680 Proposed Wording for Placement Insert (Revision 1)</a>.
</p>

<p>
If there is still an issue with pair, Howard should submit another issue.
</p>





</body>
</html>
