0

I am working on a cpp code to port one application from Windows to Mac. While building the application in Xcode it throws the error saying:

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

These errors are thrown in cpp standard library headers.

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.

  • Compiler option used to compile the application is C++ Standard Library:

    libc++(LLVM C++ Standard with C++11 support. C++ Language Dialect: GNU++11. Compiler for C++ : Apple LLVM 6.0

piet.t
  • 11,718
  • 21
  • 43
  • 52

2 Answers2

1

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...

0

A throw() specification on functions was deprecated in the '11 standard, and removed in the '17 standard. 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.

The proper thing to do in modern c++ is to use a noexcept specification. 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.

jschmerge
  • 320
  • 1
  • 4
  • Thank You. The code is compiled in C++11 only. Why the error is coming in C++ library memory file. Same time bellow mentioned error also comes. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/locale:446:13: Use of undeclared identifier '__throw_bad_alloc' in locale file. – user2262462 Aug 15 '17 at 08:15