concurrentqueue icon indicating copy to clipboard operation
concurrentqueue copied to clipboard

Compile errors when compiling as Objective-C++

Open martinfinke opened this issue 4 months ago • 0 comments

When I compile an .mm file (Objective-C++) with -fno-exceptions in Clang, __EXCEPTIONS is still #define'd to 1. So if that .mm file #includes concurrentqueue.h, it tries to use C++ exceptions, and I get compile errors because they're disabled.

It seems that __EXCEPTIONS means: "we have some kind of exception handling (including Objective-C exceptions)", and does not mean: "C++ exceptions are enabled".

This can be solved by changing the relevant line to something like this:

#if (defined(_MSC_VER) && defined(_CPPUNWIND)) || (defined(__GNUC__) && !__OBJC__ && defined(__EXCEPTIONS)) || (__OBJC__ && __has_feature(cxx_exceptions)) || (!defined(_MSC_VER) && !defined(__GNUC__))
#define MOODYCAMEL_EXCEPTIONS_ENABLED
#endif

I'm not sure whether that's the most concise and bullet-proof predicate.

The Clang docs recommend __has_feature(cxx_exceptions), though I'm not sure about backwards-compatibility.

martinfinke avatar Sep 02 '25 14:09 martinfinke