QNX provides cxxabi.h from LLVM libc++abi, which does not declare
__cxa_get_globals but provides its implementation in the library.
To make things more fun, QNX developers commented _LIBCPPABI_VERSION
definition, which breaks detection of libc++abi in uncaught_exceptions.hpp.
There is also cxxabi.h from glibcxx that does provide __cxa_get_globals
declaration. We want to use that declaration, if possible, to avoid possible
mismatch in attributes.
This commit adds non-glibcxx cxxabi.h on QNX to the list of platforms that
need our declaration of __cxa_get_globals.
Fixes https://github.com/boostorg/core/issues/59.
Travis CI shows linking errors on Linux and OS X when __cxa_uncaught_exceptions
is used to implement uncaught_exceptions. There's probably some library missing,
which should be linked in implicitly by the compiler, or the library indeed
does not export the symbol. In any case, __cxa_get_globals-based implementation
should provide the same effect.
Apparently, gcc < 4.7 on Linux also don't have __cxa_get_globals
declaration in cxxabi.h. Declare the function ourselves.
Also, on OpenBSD it seems there is no declaration either, and
on that platform the function implementation has no exception
specification, like on FreeBSD. Add a declaration of that platform.
Lastly, changed __cxa_get_globals and _getptd-based implementations
to avoid violating strict aliasing rules. This is still formally UB
to access structure fields like we do, but this is one less reason to
cause miscompilation or compiler warnings.
This should resolve gcc errors caused by mismatch of the return types of
aur declaration of __cxa_get_globals and the original in cxxabi.h.
Fixes https://github.com/boostorg/core/issues/45.
The uncaught_exceptions function is functionally equivalent to
unhandled_exceptions_count in Boost.Log and implements functionality
similar to the same named C++17 standard function. Tests and docs are
also included.
One notable difference from std::uncaught_exceptions is that the return
type is unsigned rather than signed. This is deliberate as uncaught_exceptions
must never return a negative value and unsigned int better documents that.
Theoretically, as a counter, it may also overflow.