Skip to content

Use __has_feature(cxx_exceptions) to detect C++ exceptions on Clang#454

Merged
cameron314 merged 1 commit into
cameron314:masterfrom
vsaraikin:fix/clang-has-feature-cxx-exceptions
Jul 11, 2026
Merged

Use __has_feature(cxx_exceptions) to detect C++ exceptions on Clang#454
cameron314 merged 1 commit into
cameron314:masterfrom
vsaraikin:fix/clang-has-feature-cxx-exceptions

Conversation

@vsaraikin

Copy link
Copy Markdown
Contributor

Problem

MOODYCAMEL_EXCEPTIONS_ENABLED is auto-detected from __EXCEPTIONS on Clang/GCC. On Clang, __EXCEPTIONS means "some exception handling is available" — it is set for Objective-C exceptions even when C++ exceptions are disabled (-fno-exceptions). Compiling an Objective-C++ (.mm) translation unit that includes concurrentqueue.h with -fno-exceptions therefore enables the C++ throw/try paths and fails to compile.

This is the case reported in #435.

Fix

On compilers that provide __has_feature (Clang / AppleClang), use __has_feature(cxx_exceptions) — the authoritative query for whether C++ exceptions are enabled — instead of __EXCEPTIONS. The existing MSVC/GCC predicate is kept as the fallback for compilers without __has_feature.

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

Behavior is unchanged on MSVC and GCC. On Clang, detection now tracks C++ exceptions specifically, so Objective-C++ with -fno-exceptions compiles correctly, and normal C++ builds with/without -fno-exceptions are detected as before. The user-overridable MOODYCAMEL_EXCEPTIONS_ENABLED escape hatch is untouched.

Refs #435.

Fixes MOODYCAMEL_EXCEPTIONS_ENABLED misdetection under Objective-C++,
where __EXCEPTIONS can be set for ObjC exceptions with C++ exceptions
off. Refs cameron314#435.
@vsaraikin vsaraikin marked this pull request as ready for review July 8, 2026 20:17

@cameron314 cameron314 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. Thanks.

@cameron314 cameron314 merged commit 683b9e3 into cameron314:master Jul 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants