简体   繁体   English

使用未声明的标识符“nothrow”; 您指的是 'throw' 吗? 记忆

[英]Use of undeclared identifier 'nothrow'; did you mean 'throw'? memory

I am working on a cpp code to port one application from Windows to Mac.我正在编写一个 cpp 代码来将一个应用程序从 Windows 移植到 Mac。 While building the application in Xcode it throws the error saying:在 Xcode 中构建应用程序时,它会抛出以下错误:

"Use of undeclared identifier 'nothrow'; did you mean 'throw'? memory"

These errors are thrown in cpp standard library headers.这些错误在 cpp 标准库头文件中抛出。

Below is the error stack description:以下是错误堆栈描述:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1/memory:83:8: Use of undeclared identifier 'nothrow'; did you mean 'throw'?

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1/string:48:10: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1/string:48:

I searched in internet but was unable to find the solution for this problem.我在互联网上搜索,但无法找到此问题的解决方案。 Any suggestions will be helpful.任何建议都会有所帮助。 Why the error is thrown from the system header files?为什么从系统头文件中抛出错误?

System Details:系统详情:

  • SDK is OSX 10.10. SDK 是 OSX 10.10。

  • Compiler option used to compile the application is C++ Standard Library:用于编译应用程序的编译器选项是 C++ 标准库:

    libc++(LLVM C++ Standard with C++11 support. C++ Language Dialect: GNU++11. Compiler for C++ : Apple LLVM 6.0 libc++(支持 C++11 的 LLVM C++ 标准。C++ 语言方言:GNU++11。C++ 编译器:Apple LLVM 6.0

A throw() specification on functions was deprecated in the '11 standard, and removed in the '17 standard. '11 标准中不推荐使用函数的 throw() 规范,并在 '17 标准中删除。 If clang does not support it, my guess is that that was an intentional choice on the developers' part, or you are compiling in c++17 mode.如果 clang 不支持它,我的猜测是开发人员有意选择,或者您正在以 c++17 模式进行编译。

The proper thing to do in modern c++ is to use a noexcept specification.在现代 C++ 中正确的做法是使用 noexcept 规范。 noexcept allows for more efficient code generation, in that it does not have to perform RTTI on thrown exceptions, instead if an exception is thrown from a call-frame underneath a noexcept-declared function, std::terminate is called, short-circuiting the crazy std::unexpected() machinery specified by the '98 standard. noexcept允许更有效的代码生成,因为它不必对抛出的异常执行 RTTI,相反,如果从 noexcept 声明的函数下的调用帧抛出异常,则调用 std::terminate,从而短路'98 标准指定的疯狂 std::unexpected() 机制。

In my case, this problem only occurred in debug mode.就我而言,此问题仅发生在调试模式下。 As a result of tracking down the problem, the same error occurred when the following code was declared in the header file.由于追查问题,在头文件中声明如下代码时出现同样的错误。 The code declared in the class file did not cause any problems.类文件中声明的代码没有引起任何问题。 The problem was solved by deleting the code declared in the header file.通过删除头文件中声明的代码解决了问题。

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

Hope this helps someone who is still struggling with this problem...希望这能帮助那些仍在努力解决这个问题的人......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM