<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Modifying a deque from emplace_back produces incorrect results"
   href="http://llvm.org/bugs/show_bug.cgi?id=16238">16238</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Modifying a deque from emplace_back produces incorrect results
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>hhinnant@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>felixcca@yahoo.ca
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>From my skimming into the standard, nothing specifically seems to prohibit
modifying a `std::deque` from inside `emplace_back`. Take this snippet for
example:

    #include <iostream>
    #include <deque>
    #include <string>

    using namespace std;

    struct foo
    {
        string m_marker;

        foo(deque<foo>& into, const string& marker, bool createInner = true)
        : m_marker(marker)
        {
            if (createInner)
            {
                cout << "Marker is " << m_marker << endl;
                into.emplace_back(into, "my other marker", false);
                cout << "Marker is now " << m_marker << endl;
            }
        }
    };

    int main()
    {
        deque<foo> foos;
        foos.emplace_back(foos, "my initial marker");

        cout << "There are " << foos.size() << " items in the deque:" << endl;
        for (foo& f : foos)
            cout << f.m_marker << endl;
    }

(listing also at <a href="http://stackoverflow.com/q/16955265/">http://stackoverflow.com/q/16955265/</a>)

I would expect this as the result:

<span class="quote">> Marker is my initial marker
> Marker is now my initial marker
> There are 2 items in the deque:
> my initial marker
> my other marker</span >

However, this is what I get:

<span class="quote">> Marker is my initial marker
> Marker is now my other marker
> There are 2 items in the deque:
> my other marker
>  </span >

It looks like calling `emplace_back` from within a constructor itself called
with `emplace_back` causes the deque to overwrite the first item with the
second.

I couldn't find anything that specifically prohibits modifying the container
from `emplace` methods in N3337, although I can see why this could be a
problem.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>