<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116473>116473</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Confusing error when trying to move a vector of a move-only type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vsapsai
</td>
</tr>
</table>
<pre>
The code
```c++
#include <memory>
#include <vector>
struct SomeDescription {
unsigned size;
};
struct MOType {
SomeDescription description;
MOType(const MOType &) = delete;
MOType &operator=(const MOType &) = delete;
MOType(MOType &&) = default;
MOType &operator=(MOType &&) = default;
};
void takeRValue(std::vector<MOType> &&dynArray) {
std::vector<MOType> other = dynArray;
}
void test() {
std::vector<MOType> sample;
takeRValue(std::move(sample));
}
```
[fails with the error](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:1,endLineNumber:10,positionColumn:1,positionLineNumber:10,selectionStartColumn:1,selectionStartLineNumber:10,startColumn:1,startLineNumber:10),source:'%23include+%3Cmemory%3E%0A%23include+%3Cvector%3E%0A%0Astruct+SomeDescription+%7B%0A++unsigned+size%3B%0A%7D%3B%0A%0Astruct+MOType+%7B%0A++SomeDescription+description%3B%0A%0A++MOType(const+MOType+%26)+%3D+delete%3B%0A++MOType+%26operator%3D(const+MOType+%26)+%3D+delete%3B%0A%0A++MOType(MOType+%26%26)+%3D+default%3B%0A++MOType+%26operator%3D(MOType+%26%26)+%3D+default%3B%0A%7D%3B%0A%0Avoid+takeRValue(std::vector%3CMOType%3E+%26%26dynArray)+%7B%0A++std::vector%3CMOType%3E+other+%3D+dynArray%3B%0A%7D%0A%0Avoid+test()+%7B%0A++std::vector%3CMOType%3E+sample%3B%0A++takeRValue(std::move(sample))%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:38.86323952108572,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang1910,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-stdlib%3Dlibc%2B%2B+-std%3Dc%2B%2B23',overrides:!(),selection:(endColumn:45,endLineNumber:3,positionColumn:45,positionLineNumber:3,selectionStartColumn:45,selectionStartLineNumber:3,startColumn:45,startLineNumber:3),source:1),l:'5',n:'0',o:'+x86-64+clang+19.1.0+(Editor+%231)',t:'0')),k:11.531674154618882,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+gcc+14.2',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+19.1.0+(Compiler+%231)',t:'0')),k:49.6050863242954,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
```
In file included from <source>:1:
In file included from /opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/memory:940:
In file included from /opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/__memory/allocator.h:15:
In file included from /opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/__memory/allocate_at_least.h:13:
/opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/__memory/allocator_traits.h:328:5: error: no matching function for call to '__construct_at'
328 | std::__construct_at(__p, std::forward<_Args>(__args)...);
| ^~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/__memory/uninitialized_algorithms.h:549:31: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<MOType>>::construct<MOType, MOType &, void, 0>' requested here
549 | allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__first2), *__first1);
| ^
/opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/__memory/uninitialized_algorithms.h:592:33: note: in instantiation of function template specialization 'std::__uninitialized_allocator_copy_impl<std::allocator<MOType>, MOType *, MOType *, MOType *>' requested here
592 | auto __result = std::__uninitialized_allocator_copy_impl(
| ^
/opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/vector:1158:22: note: in instantiation of function template specialization 'std::__uninitialized_allocator_copy<std::allocator<MOType>, MOType *, MOType *, MOType *>' requested here
1158 | __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
| ^
/opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/vector:800:7: note: in instantiation of function template specialization 'std::vector<MOType>::__construct_at_end<MOType *, MOType *>' requested here
800 | __construct_at_end(__first, __last, __n);
| ^
/opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/vector:1238:3: note: in instantiation of function template specialization 'std::vector<MOType>::__init_with_size<MOType *, MOType *>' requested here
1238 | __init_with_size(__x.__begin_, __x.__end_, __x.size());
| ^
<source>:19:31: note: in instantiation of member function 'std::vector<MOType>::vector' requested here
19 | std::vector<MOType> other = dynArray;
| ^
/opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/__memory/construct_at.h:47:58: note: candidate template ignored: substitution failure [with _Tp = MOType, _Args = <MOType &>]: call to deleted constructor of 'MOType'
46 | template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>
| ~~~
47 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __construct_at(_Tp* __location, _Args&&... __args) {
| ^
1 error generated.
```
As for me, the error messages aren't actionable. Compiling with `-std=c++14` is slightly better but the diagnostics are still pretty confusing.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWV2Pm7j6_zSeG2sQGAhwkYuETPSvtNuptv2veocMOIl3jc2xTabZi_PZj2wDgSRNp1V3GkUzwX7e_Hte_NhgpeieE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