C++ 确认MSVC 2015 RC中与分配器相关的标准库错误
以下是一份:C++ 确认MSVC 2015 RC中与分配器相关的标准库错误,c++,visual-c++,bug-reporting,C++,Visual C++,Bug Reporting,以下是一份: #包括 #包括 模板结构my_分配器:std::分配器{ //此重写结构导致错误 模板结构重新绑定{ typedef my_分配器其他; }; //忽略这一切。 typedef std::分配器基; typename base::pointer allocate(typename base::size_type n,std::allocator::const_pointer/*hint*/=nullptr){return(T*)malloc(sizeof(T)*n);} void释
#包括
#包括
模板结构my_分配器:std::分配器{
//此重写结构导致错误
模板结构重新绑定{
typedef my_分配器其他;
};
//忽略这一切。
typedef std::分配器基;
typename base::pointer allocate(typename base::size_type n,std::allocator::const_pointer/*hint*/=nullptr){return(T*)malloc(sizeof(T)*n);}
void释放(typename base::pointer p,typename base::size_type/*n*/){free(p);}
};
int main(int/*argc*/,char*/*argv*/[]){
std::vec;
返回0;
}
GCC喜欢它。ICC喜欢它。
叮当声喜欢它。
甚至MSVC 2013也喜欢它。
但MSVC 2015 RC指出:
1>------ Build started: Project: Test Alloc, Configuration: Debug Win32 ------
1> main.cpp
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(579): error C2664: 'void std::_Wrap_alloc<my_allocator<int>>::deallocate(int *,unsigned int)': cannot convert argument 1 from 'std::_Container_proxy *' to 'int *'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(579): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(574): note: while compiling class template member function 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)'
1> with
1> [
1> _Ty=int,
1> _Alloc=my_allocator<int>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(541): note: see reference to function template instantiation 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)' being compiled
1> with
1> [
1> _Ty=int,
1> _Alloc=my_allocator<int>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(668): note: see reference to class template instantiation 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>' being compiled
1> with
1> [
1> _Ty=int,
1> _Alloc=my_allocator<int>
1> ]
1> c:\users\ian mallett\desktop\test-alloc\main.cpp(18): note: see reference to class template instantiation 'std::vector<int,my_allocator<int>>' being compiled
1>----构建已启动:项目:测试分配,配置:调试Win32------
1> main.cpp
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\vector(579):错误C2664:“void std::\u Wrap\u alloc::deallocate(int*,unsigned int)”:无法将参数1从“std::\u Container\u proxy*”转换为“int*”
1> c:\ProgramFiles(x86)\microsoft visual studio 14.0\vc\include\vector(579):注意:指向的类型不相关;转换需要重新解释转换、C样式转换或函数样式转换
1> c:\ProgramFiles(x86)\microsoft visual studio 14.0\vc\include\vector(574):注意:在编译类模板成员函数“void std::\u vector\u alloc::\u Free\u proxy(void)”时
1> 与
1> [
1> _Ty=int,
1> \u Alloc=我的\u分配器
1> ]
1> c:\ProgramFiles(x86)\microsoft visual studio 14.0\vc\include\vector(541):注意:请参阅正在编译的函数模板实例化“void std::\u vector\u alloc::\u Free\u proxy(void)”的参考
1> 与
1> [
1> _Ty=int,
1> \u Alloc=我的\u分配器
1> ]
1> c:\ProgramFiles(x86)\microsoft visual studio 14.0\vc\include\vector(668):注意:请参阅正在编译的类模板实例化“std::\u vector\u alloc”的参考
1> 与
1> [
1> _Ty=int,
1> \u Alloc=我的\u分配器
1> ]
1> c:\users\ian mallett\desktop\test alloc\main.cpp(18):注意:请参阅正在编译的类模板实例化“std::vector”的参考
相关程序给出了类似的可疑错误。这里有两个:错误C2664:“void std::\u Wrap\u alloc>::解除分配(int*,unsigned int)”:无法将参数1从“std::\u Container\u proxy*”转换为“int*”
无法将参数1从“std::\u Wrap\u alloc>”转换为“const aligned\u allocator&” 布尔问题:这是一个bug吗?如果是,我将()提交 [编辑:如注释中所述,这仅在调试模式下发生。在发布模式下,它编译和执行良好。] [编辑:更简单的示例] 布尔问题:这是一个bug吗
false
虽然MSVC在这里给出的模板错误毫无帮助,但这里的错误是我的(因为标准库的这个版本今天已经发布了,所以让人放心) 我从各种来源创建了这个分配器(以及后来的简化测试用例),这就是为什么我认为它是正确的。然而,正如评论中所建议的那样,我再次检查了一遍,这一次彻底检查了文档 这里缺少的组件是一个复制构造函数(无法自动生成的模板构造函数)。这仅在定义了
rebind
结构时显示,因为rebind
结构重写父类中的同一个结构(由于它在父类中,最终导致调用父类的复制构造函数,所以没有问题(除了技术上错误)
有趣的是,这个错误直到现在才发生。正如我所说,GCC、Clang和MSVC2013都喜欢它(即使有各自的调试模式)。只是这些都没有调用模板复制构造函数。然而,这是由标准规定的,因此,错误最终还是我的
祝贺MSVC编译器团队,并为噪音道歉!:D可能不相关,但将声明添加到命名空间
std
是不正确的。有异常,请参阅。@CaptainObvlious我认为这些异常在这里都不适用。如果您关闭MSVC标准库的诊断模式会怎么样?这只是错误代码,您不支持重新绑定。在许多地方,您可以找到如何创建自己的分配器类型,这里没有什么需要重复的:)感谢您的明确回答,我遇到了完全相同的问题,您可能为我节省了一些时间!
1>------ Build started: Project: Test Alloc, Configuration: Debug Win32 ------
1> main.cpp
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(579): error C2664: 'void std::_Wrap_alloc<my_allocator<int>>::deallocate(int *,unsigned int)': cannot convert argument 1 from 'std::_Container_proxy *' to 'int *'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(579): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(574): note: while compiling class template member function 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)'
1> with
1> [
1> _Ty=int,
1> _Alloc=my_allocator<int>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(541): note: see reference to function template instantiation 'void std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Free_proxy(void)' being compiled
1> with
1> [
1> _Ty=int,
1> _Alloc=my_allocator<int>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(668): note: see reference to class template instantiation 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>' being compiled
1> with
1> [
1> _Ty=int,
1> _Alloc=my_allocator<int>
1> ]
1> c:\users\ian mallett\desktop\test-alloc\main.cpp(18): note: see reference to class template instantiation 'std::vector<int,my_allocator<int>>' being compiled