Код: Выделить всё
#include
#include
#include
int main() {
std::vector vector;
vector.emplace_back(); // this fails to compile
}
На первый взгляд это та же проблема, что и ранее решенная в этом разделе. вопрос Ошибка компилятора с вектором deque unique_ptr .
Однако приведенное там объяснение больше не применимо, поскольку конструктор перемещения std::deque был создан noException в C++17 и определяется как noException(_Alty_traits::is_always_equal::value), который оценивается как noException(true) для стандартного std::allocator.
Это изменение решило проблему как в gcc, так и в clang. Однако в MSVC (и clang-cl), несмотря на то, что реализация конструктора перемещения std::deque была обновлена таким же образом, проблема остается, и достигается конструктор копирования std::unique_ptr.
Вот ошибка компилятора:
Код: Выделить всё
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\xmemory(698,9): error : no matching function for call to 'construct_at'
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\yvals_core.h(1894,17): message : expanded from macro '_STD'
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\deque(1138,23): message : in instantiation of function template specialization 'std::_Default_allocator_traits::construct' requested here
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\deque(723,13): message : in instantiation of function template specialization 'std::deque::_Emplace_back_internal' requested here
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\deque(685,9): message : in instantiation of function template specialization 'std::deque::_Construct' requested here
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\xutility(390,66): message : in instantiation of member function 'std::deque::deque' requested here
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\xutility(388,16): message : candidate template ignored: constraints not satisfied [with _Ty = std::unique_ptr, _Types = ]
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\xutility(386,47): message : because '::new (static_cast(_Location)) _Ty(::std::forward(_Args)...)' would be invalid: call to deleted constructor of 'std::unique_ptr'
Подробнее здесь: https://stackoverflow.com/questions/791 ... or-in-msvc
Мобильная версия