草庐IT

fno-implicit-templates

全部标签

c++ - GCC/VS2008 : Different behaviour of function call when templated base class is derived from itself

以下代码适用于VisualStudio2008,但不适用于GCC/G++4.3.420090804。根据C++标准,哪种行为正确?templatestructA:A{};templatestructA{};structB:A{};templatevoidFunc(constA&a){}intmain(){Aa;//isderivedfromAFunc(a);//vs2008:ok,g++:ok//Comeau:okBb;//isderivedfromAFunc(b);//vs2008:ok,g++:error,nomatchingfunctionforcalltoFunc(B&)//C

c++ - 从 Josuttis : Do different template functions, 实例化到给定特定类型的相同函数签名,导致 ODR 无效?

在Josuttis和Vandevoorde关于模板的著名著作中,C++Templates:TheCompleteGuide,他们讨论了有关函数模板重载的细节。在他们的一个示例中,与函数签名和重载函数模板的讨论相关,他们提供了用以下术语描述的代码:Thisprogramisvalidandproducesthefollowingoutput:(Note:Outputshownbelow)但是,当我在VisualStudio2010中构建和编译相同的代码时,我得到了不同的结果。这让我相信要么是VS2010编译器生成了错误的代码,要么是Josuttis错误地认为代码有效。这是代码。(Josu

c++ - 从 Josuttis : Do different template functions, 实例化到给定特定类型的相同函数签名,导致 ODR 无效?

在Josuttis和Vandevoorde关于模板的著名著作中,C++Templates:TheCompleteGuide,他们讨论了有关函数模板重载的细节。在他们的一个示例中,与函数签名和重载函数模板的讨论相关,他们提供了用以下术语描述的代码:Thisprogramisvalidandproducesthefollowingoutput:(Note:Outputshownbelow)但是,当我在VisualStudio2010中构建和编译相同的代码时,我得到了不同的结果。这让我相信要么是VS2010编译器生成了错误的代码,要么是Josuttis错误地认为代码有效。这是代码。(Josu

c++ - BOOST_NO_EXCEPTIONS 是否保证与 -fno-exceptions 兼容?

我想将Boost.Filesystem与-fno-exceptions一起使用。根据Boost.Filesystemdocumentation它声明它支持BOOST_NO_EXCEPTIONS宏。但是,以下snippet:#defineBOOST_NO_EXCEPTIONS#includeintmain(){}编译:g++-fno-exceptionsboost_test.cpp给出错误:/.../boost/filesystem/operations.hpp:Inconstructor'boost::filesystem::filesystem_error::filesystem_e

c++ - BOOST_NO_EXCEPTIONS 是否保证与 -fno-exceptions 兼容?

我想将Boost.Filesystem与-fno-exceptions一起使用。根据Boost.Filesystemdocumentation它声明它支持BOOST_NO_EXCEPTIONS宏。但是,以下snippet:#defineBOOST_NO_EXCEPTIONS#includeintmain(){}编译:g++-fno-exceptionsboost_test.cpp给出错误:/.../boost/filesystem/operations.hpp:Inconstructor'boost::filesystem::filesystem_error::filesystem_e

c++ - 此错误消息是否正确 : non-type template argument is not a constant expression

以下程序可以使用GCC5.2编译,但不能使用clang3.6:constexprboolflag();templateconstexprbooltest(){returnb;}intmain(){}我用clang得到的错误信息是:main.cpp:3:20:error:non-typetemplateargumentisnotaconstantexpressiontemplate^~~~~~main.cpp:3:20:note:undefinedfunction'flag'cannotbeusedinaconstantexpressionmain.cpp:1:16:note:decla

c++ - 此错误消息是否正确 : non-type template argument is not a constant expression

以下程序可以使用GCC5.2编译,但不能使用clang3.6:constexprboolflag();templateconstexprbooltest(){returnb;}intmain(){}我用clang得到的错误信息是:main.cpp:3:20:error:non-typetemplateargumentisnotaconstantexpressiontemplate^~~~~~main.cpp:3:20:note:undefinedfunction'flag'cannotbeusedinaconstantexpressionmain.cpp:1:16:note:decla

c++ - (template) rebind<> 做什么?

为了进一步了解标准库的实际实现方式,我正在检查VisualStudio中的所有容器。这里我看到了一些奇怪的结构:在std::list的某些基类中找到以下typedeftypedeftypename_Alloc::templaterebind::other_Alty;其中“_Alloc”对应于分配器模板参数(和_Ty包含的类型)。我很难找到这个“关键字”的一个很好的解释。到目前为止我发现的最好的事情是它是分配器接口(interface)的一部分。虽然甚至cppreference不太好解释这个。这是什么templaterebind做?为什么在那个位置有必要? 最

c++ - (template) rebind<> 做什么?

为了进一步了解标准库的实际实现方式,我正在检查VisualStudio中的所有容器。这里我看到了一些奇怪的结构:在std::list的某些基类中找到以下typedeftypedeftypename_Alloc::templaterebind::other_Alty;其中“_Alloc”对应于分配器模板参数(和_Ty包含的类型)。我很难找到这个“关键字”的一个很好的解释。到目前为止我发现的最好的事情是它是分配器接口(interface)的一部分。虽然甚至cppreference不太好解释这个。这是什么templaterebind做?为什么在那个位置有必要? 最

c++ - 成员函数模板不能声明为虚拟 - 来自 Addison Wesley : C++ Templates

来自AddisonWesley:C++模板Memberfunctiontemplatescannotbedeclaredvirtual.Thisconstraintisimposedbecausetheusualimplementationofthevirtualfunctioncallmechanismusesafixed-sizetablewithoneentrypervirtualfunction.However,thenumberofinstantiationsofamemberfunctiontemplateisnotfixeduntiltheentireprogramhas