草庐IT

noexcept-ness

全部标签

c++ - 为什么 noexcept 在编译时不强制执行?

您可能知道C++11有noexcept关键字。现在丑陋的部分是这样的:Notethatanoexceptspecificationonafunctionisnotacompile-timecheck;itismerelyamethodforaprogrammertoinformthecompilerwhetherornotafunctionshouldthrowexceptions.http://en.cppreference.com/w/cpp/language/noexcept_spec那么这是委员会部分的设计失败,还是他们只是将其作为编译作者的练习:)从某种意义上说,体面的编译器

c++ - 为什么 noexcept 在编译时不强制执行?

您可能知道C++11有noexcept关键字。现在丑陋的部分是这样的:Notethatanoexceptspecificationonafunctionisnotacompile-timecheck;itismerelyamethodforaprogrammertoinformthecompilerwhetherornotafunctionshouldthrowexceptions.http://en.cppreference.com/w/cpp/language/noexcept_spec那么这是委员会部分的设计失败,还是他们只是将其作为编译作者的练习:)从某种意义上说,体面的编译器

c++ - 为什么 std::array::front 和 std::array::back 不是 noexcept?

我不熟悉noexcept说明符的使用,我不明白为什么std::array::front和std::array::back未声明noexcept(而std::array::begin和std::array::end是).这是什么原因? 最佳答案 来自cppreferenceThereisaspecialcaseforazero-lengtharray(N==0).Inthatcase,array.begin()==array.end(),whichissomeuniquevalue.Theeffectofcallingfront()o

c++ - 为什么 std::array::front 和 std::array::back 不是 noexcept?

我不熟悉noexcept说明符的使用,我不明白为什么std::array::front和std::array::back未声明noexcept(而std::array::begin和std::array::end是).这是什么原因? 最佳答案 来自cppreferenceThereisaspecialcaseforazero-lengtharray(N==0).Inthatcase,array.begin()==array.end(),whichissomeuniquevalue.Theeffectofcallingfront()o

c++ - 具有默认参数构造的 noexcept 说明符

以下面的示例代码为例:voidtest(constItem&item=Item()){...}假设一旦item被传递给函数,this就不能抛出。问题是:函数应该标记为noexcept还是noexcept(noexcept(Item()))?IHMO,前者应该没问题,但我不确定。非常感谢标准的引用! 最佳答案 默认参数是函数调用者的快捷符号。所以,当函数执行时,构造就已经完成了。因此,noexcept应该就足够了。在standard[dcl.fct.default]状态:Ifaninitializer-clauseisspecifie

c++ - 具有默认参数构造的 noexcept 说明符

以下面的示例代码为例:voidtest(constItem&item=Item()){...}假设一旦item被传递给函数,this就不能抛出。问题是:函数应该标记为noexcept还是noexcept(noexcept(Item()))?IHMO,前者应该没问题,但我不确定。非常感谢标准的引用! 最佳答案 默认参数是函数调用者的快捷符号。所以,当函数执行时,构造就已经完成了。因此,noexcept应该就足够了。在standard[dcl.fct.default]状态:Ifaninitializer-clauseisspecifie

c++ - 在 C++17 中使用 noexcept 的 std::function

在C++17中noexcepthasbeenaddedtothetypesystem:voidr1(void(*f)()noexcept){f();}voidfoo(){throw1;}intmain(){r1(foo);}最新版本的C++17模式的GCC和Clang拒绝调用r1(foo),因为void(*)()不能隐式转换为void(*)()noexcept.但是对于std::function而是:#includevoidr2(std::functionf){f();}voidfoo(){throw1;}intmain(){r2(foo);}Clang接受程序,显然忽略了noexce

c++ - 在 C++17 中使用 noexcept 的 std::function

在C++17中noexcepthasbeenaddedtothetypesystem:voidr1(void(*f)()noexcept){f();}voidfoo(){throw1;}intmain(){r1(foo);}最新版本的C++17模式的GCC和Clang拒绝调用r1(foo),因为void(*)()不能隐式转换为void(*)()noexcept.但是对于std::function而是:#includevoidr2(std::functionf){f();}voidfoo(){throw1;}intmain(){r2(foo);}Clang接受程序,显然忽略了noexce

c++ - C++ 标准是否要求 C 链接函数为 `noexcept` ?

我在标准中找不到任何强制使用extern"C"声明的函数为noexcept的内容,无论是隐式还是显式。然而,应该清楚的是,C调用约定不能支持异常......或者是吗?标准是否在我错过的地方提到了这一点?如果不是,为什么不呢?它只是作为某种实现细节留下来吗? 最佳答案 据我所知,不能保证使用“C”链接定义的函数不会引发异常。该标准允许C++程序调用具有“C”语言链接的外部函数,并定义用C++编写的具有“C”语言链接的函数。因此,没有什么可以阻止C++程序调用具有“C”语言链接的函数,该函数实际上是用C++编写的(可能在另一个编译单元中

c++ - C++ 标准是否要求 C 链接函数为 `noexcept` ?

我在标准中找不到任何强制使用extern"C"声明的函数为noexcept的内容,无论是隐式还是显式。然而,应该清楚的是,C调用约定不能支持异常......或者是吗?标准是否在我错过的地方提到了这一点?如果不是,为什么不呢?它只是作为某种实现细节留下来吗? 最佳答案 据我所知,不能保证使用“C”链接定义的函数不会引发异常。该标准允许C++程序调用具有“C”语言链接的外部函数,并定义用C++编写的具有“C”语言链接的函数。因此,没有什么可以阻止C++程序调用具有“C”语言链接的函数,该函数实际上是用C++编写的(可能在另一个编译单元中