tgockel / json-voorhees

A killer modern C++ library for interacting with JSON.
http://tgockel.github.io/json-voorhees/
Apache License 2.0
128 stars 18 forks source link

Use __has_include to detect <cxxabi.h> in demangle.cpp #129

Closed tgockel closed 5 years ago

tgockel commented 5 years ago

detail/demangle.cpp uses an inaccurate detection mechanism for <cxxabi.h>:

#ifndef _MSC_VER
#include <cxxabi.h>
#endif

Changeset 2afc956338eba5b8de237701b60dc1cf251a3569 introduced another usage of <cxxabi.h> to read the exception type name:

#if __cplusplus >= 201703L
#   if __has_include(<cxxabi.h>)
#       define JSONV_HAS_CXXABI 1
#       include <cxxabi.h>
#   else
#       define JSONV_HAS_CXXABI 0
#   endif
#else
#   define JSONV_HAS_CXXABI 0
#endif

This is the C++17 approved detection mechanism, but changing it in a minor release would potentially be a breaking behavior change, as pre-C++17 compilers are not guaranteed to support __has_include, so this would break GCC and Clang compiling in C++11 and C++14 mode. GCC offers a non-portable solution in #if defined __has_include && __has_include(<cxxabi.h>), but this breaks the entire point. We might be able to do it on multiple lines and just rock it.

tgockel commented 5 years ago

This can be done in a backward-compatible manner.