[llvm-bugs] [Bug 27442] New: std::vector emplace_back instantiates implicitly-deleted copy constructor
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Apr 20 14:51:26 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=27442
Bug ID: 27442
Summary: std::vector emplace_back instantiates
implicitly-deleted copy constructor
Product: libc++
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: dexonsmith at apple.com
CC: dblaikie at gmail.com, george.burgess.iv at gmail.com,
llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
Classification: Unclassified
Created attachment 16242
--> https://llvm.org/bugs/attachment.cgi?id=16242&action=edit
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> >
>::__construct<Wrapper<NonCopyable>, const Wrapper<NonCopyable> &>' requested
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> >
>::construct<Wrapper<NonCopyable>, const Wrapper<NonCopyable> &>' requested
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> >
>::__construct_backward<Wrapper<NonCopyable> *>' requested here
__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> >
>::__emplace_back_slow_path<int>' requested here
__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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160420/10248e68/attachment.html>
More information about the llvm-bugs
mailing list