gpt4 book ai didi

c++ - 数组 vector 编译失败

转载 作者:行者123 更新时间:2023-12-03 22:58:52 27 4
gpt4 key购买 nike

<分区>

这个简单的程序

#include <vector>

int main()
{
using int3 = int[3];
std::vector<int3> vec( 2 );
}

未在最新的 Visual Studio 2019 16.10.0 中使用 stdcpplatest 开关编译,产生错误:

>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xutility(144,1): error C2440: 'return': cannot convert from 'int *' to '_Ty (*)'
1> with
1> [
1> _Ty=int [3]
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xutility(144,48): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xmemory(707): message : see reference to function template instantiation '_Ty (*std::construct_at<_Objty,,void>(_Ty (*const )) noexcept)[3]' being compiled
1> with
1> [
1> _Ty=int [3],
1> _Objty=int [3]
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xmemory(1610): message : see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,>(_Alloc &,_Objty (*const ))' being compiled
1> with
1> [
1> _Alloc=std::allocator<int3>,
1> _Ty=int [3],
1> _Objty=int [3]
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xmemory(1611): message : see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,>(_Alloc &,_Objty (*const ))' being compiled
1> with
1> [
1> _Alloc=std::allocator<int3>,
1> _Ty=int [3],
1> _Objty=int [3]
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xmemory(1811): message : see reference to function template instantiation 'void std::_Uninitialized_backout_al<_Alloc>::_Emplace_back<>(void)' being compiled
1> with
1> [
1> _Alloc=std::allocator<int3>
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xmemory(1811): message : see reference to function template instantiation 'void std::_Uninitialized_backout_al<_Alloc>::_Emplace_back<>(void)' being compiled
1> with
1> [
1> _Alloc=std::allocator<int3>
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\vector(1648): message : see reference to function template instantiation 'int (*std::_Uninitialized_value_construct_n<std::allocator<int3>>(int (*)[3],unsigned __int64,_Alloc &))[3]' being compiled
1> with
1> [
1> _Alloc=std::allocator<int3>
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\vector(1646): message : while compiling class template member function 'int (*std::vector<int3,std::allocator<int3>>::_Ufill(int (*)[3],const unsigned __int64,std::_Value_init_tag))[3]'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\vector(493): message : see reference to function template instantiation 'int (*std::vector<int3,std::allocator<int3>>::_Ufill(int (*)[3],const unsigned __int64,std::_Value_init_tag))[3]' being compiled
1>Test.cpp(271): message : see reference to class template instantiation 'std::vector<int3,std::allocator<int3>>' being compiled
1>Done building project "Project1.vcxproj" -- FAILED.

该程序在以前版本的 Visual Studio 2019 16.9.5 和 gcc 11 中编译良好,但在 clang 5 中也无法编译。std::vector of array 是标准允许的还是特定于实现的行为?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com