<html>
    <head>
      <base href="https://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 --- - std::vector emplace_back instantiates implicitly-deleted copy constructor"
   href="https://llvm.org/bugs/show_bug.cgi?id=27442">27442</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::vector emplace_back instantiates implicitly-deleted copy constructor
          </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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dexonsmith@apple.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dblaikie@gmail.com, george.burgess.iv@gmail.com, llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16242" name="attach_16242" title="t.cpp">attachment 16242</a> <a href="attachment.cgi?id=16242&action=edit" title="t.cpp">[details]</a></span>
t.cpp

Using r266855, given:
--
#include <vector>

struct NonCopyable {
  NonCopyable(int);
  NonCopyable(NonCopyable&&);
};

template <class T> struct Wrapper {
  T value;
  Wrapper(int value) : value(value) {}
  Wrapper(Wrapper &&X) : value(std::move(X.value)) {}
  Wrapper(const Wrapper &X) : value(X.value) {}
};

void foo() {
  std::vector<Wrapper<NonCopyable>> vector;
  vector.emplace_back(5);
}
--

I get the following:
--
$ path/to/clang -nostdinc++ -isystem path/to/libcxx -std=c++11 t.cpp
-fsyntax-only
t.cpp:12:31: error: call to implicitly-deleted copy constructor of
'NonCopyable'
  Wrapper(const Wrapper &X) : value(X.value) {}
                              ^     ~~~~~~~
/Users/dexonsmith/data/llvm/llvm.org/projects/libcxx/include/memory:1748:31:
note: in instantiation of member function 'Wrapper<NonCopyable>::Wrapper'
requested here
            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
                              ^
/Users/dexonsmith/data/llvm/llvm.org/projects/libcxx/include/memory:1656:18:
note: in instantiation of function template specialization
'std::__1::allocator<Wrapper<NonCopyable>
      >::construct<Wrapper<NonCopyable>, const Wrapper<NonCopyable> &>'
requested here
            {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
                 ^
/Users/dexonsmith/data/llvm/llvm.org/projects/libcxx/include/memory:1502:14:
note: in instantiation of function template specialization
      'std::__1::allocator_traits<std::__1::allocator<Wrapper<NonCopyable> >
<span class="quote">>::__construct<Wrapper<NonCopyable>, const Wrapper<NonCopyable> &>' requested</span >
here
            {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
             ^
/Users/dexonsmith/data/llvm/llvm.org/projects/libcxx/include/memory:1618:17:
note: in instantiation of function template specialization
      'std::__1::allocator_traits<std::__1::allocator<Wrapper<NonCopyable> >
<span class="quote">>::construct<Wrapper<NonCopyable>, const Wrapper<NonCopyable> &>' requested</span >
here
                construct(__a, _VSTD::__to_raw_pointer(__end2-1),
_VSTD::move_if_noexcept(*--__end1));
                ^
/Users/dexonsmith/data/llvm/llvm.org/projects/libcxx/include/vector:892:21:
note: in instantiation of function template specialization
      'std::__1::allocator_traits<std::__1::allocator<Wrapper<NonCopyable> >
<span class="quote">>::__construct_backward<Wrapper<NonCopyable> *>' requested here</span >
    __alloc_traits::__construct_backward(this->__alloc(), this->__begin_,
this->__end_, __v.__begin_);
                    ^
/Users/dexonsmith/data/llvm/llvm.org/projects/libcxx/include/vector:1629:5:
note: in instantiation of member function
'std::__1::vector<Wrapper<NonCopyable>,
      std::__1::allocator<Wrapper<NonCopyable> > >::__swap_out_circular_buffer'
requested here
    __swap_out_circular_buffer(__v);
    ^
/Users/dexonsmith/data/llvm/llvm.org/projects/libcxx/include/vector:1648:9:
note: in instantiation of function template specialization
'std::__1::vector<Wrapper<NonCopyable>,
      std::__1::allocator<Wrapper<NonCopyable> >
<span class="quote">>::__emplace_back_slow_path<int>' requested here</span >
        __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
        ^
t.cpp:17:10: note: in instantiation of function template specialization
'std::__1::vector<Wrapper<NonCopyable>,
std::__1::allocator<Wrapper<NonCopyable> > >::emplace_back<int>' requested here
  vector.emplace_back(5);
         ^
t.cpp:5:3: note: copy constructor is implicitly deleted because 'NonCopyable'
has a user-declared move constructor
  NonCopyable(NonCopyable&&);
  ^
1 error generated.
--

Commenting out `Wrapper(const Wrapper &X)` will let it compile.  It's not clear
why having the extra (implicitly deleted) constructor around causes
emplace_back to fail to compile.

This compile error scared me enough that I committed r266909 to stop using
std::vector on types that are expensive to copy.</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>