草庐IT

nothrow_t

全部标签

c++ - 哪些适用于 Windows 的 C++11 编译器支持新的类型特征,例如 "is_nothrow_move_constructible"?

是否有支持新的C++11类型特征的适用于Windows的C++11编译器,例如is_nothrow_move_constructible?我试图编写一个支持它的容器,却发现我的编译器(VC++2010、TDMMinGW32GCC4.6)都不支持它... 最佳答案 对于mingw,我推荐STL'sdistrohere(海湾合作委员会4.7.1)。它还带有boost1.50。还有mingw-w64(原始mingw的一个分支),我推荐rubenvb'spersonalbuildshere.转到ToolchainstargettingWin

java - 是否有任何标准注释来指示 Java 中的 nothrow 语义?

我想在Java中记录一个接口(interface)方法,因为不允许传播异常,并进行某种静态分析来验证此方法的实现是否捕获并处理可能传播给它的任何异常。类似于@NoThrow。例如,我希望能够写:interfaceSomeServiceProviderInterface{@NoThrow@NonNullSomeResultsomeComputation();}...并保证实现遵守此接口(interface)契约(Contract)。是否有注释和静态分析工具已经可以做到这一点?如果没有,有谁知道这是否可以通过注释处理器实现(它可以查看代码是否包含try...catchblock?)和/或对

c++ - 在 extern C 中使用 _attribute__ ((nothrow)) 有意义吗?

我有一些从C++调用的C代码。header类似于以下内容:#ifndefCLibH#defineCLibH#ifdef__cplusplusextern"C"{#endif//CAPIvoidfoo(void);//...#ifdef__cplusplus}#endif#endif由于我已经在使用externC,添加nothrow编译器属性有什么好处吗?#ifndefCLibH#defineCLibH#ifdef__cplusplusextern"C"{#endif//CAPIvoidfoo(void)__attribute__((nothrow));//...#ifdef__cplu

c++ - std::nothrow 未按预期工作 - 条件始终为假

#includeintmain(){int*xx=new(std::nothrow)int[2];if(xx==NULL){exit(1);}return0;}我正在尝试使用nothrow,但是clion说关于xx==NULL“条件始终为假”,以及关于exit(1)那个“无法访问的代码”。我做错了什么? 最佳答案 这是CLion中的错误-CPP-989 关于c++-std::nothrow未按预期工作-条件始终为假,我们在StackOverflow上找到一个类似的问题:

c++ - std::string not nothrow move assignable or comparable?

我在研究type_traits时,发现了std::string的这个奇怪属性:$cata.cpp#include#includestatic_assert(std::is_nothrow_move_assignable::value,"???");static_assert(noexcept(std::declval()==std::declval()),"???");$g++-std=c++14a.cppa.cpp:4:1:error:staticassertionfailed:???static_assert(std::is_nothrow_move_assignable::val

c++ - C++ 是否有办法忽略函数的异常?

我创建了一个抛出异常的函数,但在某些情况下我希望它简单地忽略这个异常。我的代码是这样写的,但不是很优雅:try{myFunction();}catch(...){}C++有没有另一种写法? 最佳答案 不,没有。在这种情况下,您可以按照标准执行的操作,即重载函数两次,一次使用std::nothrow_t一次没有。用后者包裹第一个std::error_codemy_function(std::nothrow_t)noexcept;voidmy_function();//throws 关于c+

c++ - 对于具有抛出复制构造函数和 noexcept 按值复制赋值的类,is_nothrow_copy_assignable 的值是多少?

根据C++标准,以下程序的预期(如果有)输出是什么:#include#include#includeclassA{public:A()=default;~A()=default;A(Aconst&other){}A(A&&other)noexcept{}A&operator=(Aother)noexcept{return*this;}};intmain(){std::cout::value::value换句话说,类型特征值的评估是否只看赋值运算符的声明,即noexcept,并因此产生truetrue或者它是否考虑调用上下文(a、b是A的实例)a=b;//maythrow,implici

c++ - 带有 nothrow 选项的 Operator new 仍然抛出异常

有这样的代码:#includeintmain(){for(;;){int*ptr=new(std::nothrow)int;if(ptr==0){std::cout然而,这个程序仍然抛出std::bac_alloc异常,尽管new是用std::nothrow参数调用的。该程序在VisualC++2010中编译,为什么会抛出异常?编辑:在Windows上从mingw使用g++,一切正常。 最佳答案 0必须格式化为"0"。这将占用几个字节;我敢打赌这就是原因。在std::bad_alloc::bad_alloc上放置一个断点,你就会知道

c++ - 为什么 vector 被认为是 nothrow_move_constructible?

vector的移动构造函数的规范是(从标准中复制出来的):vector(vector&&);注意缺少noexcept.但是gcc4.8和Clang3.2都报告了std::is_nothrow_move_constructible>::value返回真(即1):#include#includeintmain(){std::cout>::value造成这种明显差异的原因是什么? 最佳答案 标准允许实现根据方法加强异常规范17.6.5.12Restrictionsonexceptionhandling[res.on.exception.h

c++ - 构造函数被继承时的 std::is_nothrow_constructible

考虑以下两个示例:structA{A()noexcept=default;};structB:A{B()noexcept=default;templateB(T)noexcept{}};structC:A{usingA::A;templateC(T)noexcept{}};和用法:std::cout::value::value::value::value输出是:1101使用的编译器:GCC4.8.1。因此,如果我显式编写默认的B构造函数,(X)会生成1,另一方面,如果默认的C构造函数可用由于继承,(Y)产生0。这是为什么?这是否意味着在使用is_nothrow_constructibl