Use __has_feature(cxx_exceptions) to detect C++ exceptions on Clang#454
Open
vsaraikin wants to merge 1 commit into
Open
Use __has_feature(cxx_exceptions) to detect C++ exceptions on Clang#454vsaraikin wants to merge 1 commit into
vsaraikin wants to merge 1 commit into
Conversation
Fixes MOODYCAMEL_EXCEPTIONS_ENABLED misdetection under Objective-C++, where __EXCEPTIONS can be set for ObjC exceptions with C++ exceptions off. Refs cameron314#435.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MOODYCAMEL_EXCEPTIONS_ENABLEDis auto-detected from__EXCEPTIONSon Clang/GCC. On Clang,__EXCEPTIONSmeans "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 includesconcurrentqueue.hwith-fno-exceptionstherefore enables the C++throw/trypaths 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.Behavior is unchanged on MSVC and GCC. On Clang, detection now tracks C++ exceptions specifically, so Objective-C++ with
-fno-exceptionscompiles correctly, and normal C++ builds with/without-fno-exceptionsare detected as before. The user-overridableMOODYCAMEL_EXCEPTIONS_ENABLEDescape hatch is untouched.Refs #435.