mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 06:35:12 +00:00
Update PYBIND11_CPP1{4,7} macros for MSVC
The PYBIND11_CPP14 macro started out as a guard for the compile-time path code in `descr.h`, but has since come to mean other things. This means that while the `descr.h` check has just checked the `PYBIND11_CPP14` macro, various other places now check `PYBIND11_CPP14 || _MSC_VER`. This reverses that by now setting the CPP14 macro when MSVC is trying to support C++14, but disabling the `descr.h` C++14 code (which still fails under MSVC 2017). The CPP17 macro also gets enabled when MSVC 2017 is compiling with /std:c++latest (the default is /std:c++14), which enables `std::optional` and `std::variant` support under MSVC.
This commit is contained in:
parent
d15b217f1a
commit
ca0e82b79f
@ -16,9 +16,6 @@
|
||||
# define NAMESPACE_END(name) }
|
||||
#endif
|
||||
|
||||
// Neither MSVC nor Intel support enough of C++14 yet (in particular, as of MSVC 2015 and ICC 17
|
||||
// beta, neither support extended constexpr, which we rely on in descr.h), so don't enable pybind
|
||||
// CPP14 features for them.
|
||||
#if !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
|
||||
# if __cplusplus >= 201402L
|
||||
# define PYBIND11_CPP14
|
||||
@ -26,6 +23,14 @@
|
||||
# define PYBIND11_CPP17
|
||||
# endif
|
||||
# endif
|
||||
#elif defined(_MSC_VER)
|
||||
// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented)
|
||||
# if _MSVC_LANG >= 201402L
|
||||
# define PYBIND11_CPP14
|
||||
# if _MSVC_LANG > 201402L && _MSC_VER >= 1910
|
||||
# define PYBIND11_CPP17
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Compiler version assertions
|
||||
@ -69,7 +74,7 @@
|
||||
# define PYBIND11_NOINLINE __attribute__ ((noinline))
|
||||
#endif
|
||||
|
||||
#if defined(PYBIND11_CPP14) || defined(_MSC_VER)
|
||||
#if defined(PYBIND11_CPP14)
|
||||
# define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]]
|
||||
#else
|
||||
# define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
|
||||
@ -339,7 +344,7 @@ struct internals {
|
||||
inline internals &get_internals();
|
||||
|
||||
/// from __cpp_future__ import (convenient aliases from C++14/17)
|
||||
#ifdef PYBIND11_CPP14
|
||||
#if defined(PYBIND11_CPP14) && (!defined(_MSC_VER) || _MSC_VER >= 1910)
|
||||
using std::enable_if_t;
|
||||
using std::conditional_t;
|
||||
using std::remove_cv_t;
|
||||
@ -350,7 +355,7 @@ template <typename T> using remove_cv_t = typename std::remove_cv<T>::type;
|
||||
#endif
|
||||
|
||||
/// Index sequences
|
||||
#if defined(PYBIND11_CPP14) || defined(_MSC_VER)
|
||||
#if defined(PYBIND11_CPP14)
|
||||
using std::index_sequence;
|
||||
using std::make_index_sequence;
|
||||
#else
|
||||
@ -622,8 +627,8 @@ struct error_scope {
|
||||
/// Dummy destructor wrapper that can be used to expose classes with a private destructor
|
||||
struct nodelete { template <typename T> void operator()(T*) { } };
|
||||
|
||||
// overload_cast requires variable templates: C++14 or MSVC
|
||||
#if defined(PYBIND11_CPP14) || defined(_MSC_VER)
|
||||
// overload_cast requires variable templates: C++14
|
||||
#if defined(PYBIND11_CPP14)
|
||||
#define PYBIND11_OVERLOAD_CAST 1
|
||||
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
@ -15,7 +15,9 @@
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
#if defined(PYBIND11_CPP14) /* Concatenate type signatures at compile time using C++14 */
|
||||
/* Concatenate type signatures at compile time using C++14 */
|
||||
#if defined(PYBIND11_CPP14) && !defined(_MSC_VER)
|
||||
#define PYBIND11_CONSTEXPR_DESCR
|
||||
|
||||
template <size_t Size1, size_t Size2> class descr {
|
||||
template <size_t Size1_, size_t Size2_> friend class descr;
|
||||
|
@ -252,7 +252,7 @@ protected:
|
||||
if (type_depth != 0 || types[type_index] != nullptr)
|
||||
pybind11_fail("Internal error while parsing type signature (2)");
|
||||
|
||||
#if !defined(PYBIND11_CPP14)
|
||||
#if !defined(PYBIND11_CONSTEXPR_DESCR)
|
||||
delete[] types;
|
||||
delete[] text;
|
||||
#endif
|
||||
|
@ -41,6 +41,11 @@
|
||||
# include <variant>
|
||||
# define PYBIND11_HAS_VARIANT 1
|
||||
# endif
|
||||
#elif defined(_MSC_VER) && defined(PYBIND11_CPP17)
|
||||
# include <optional>
|
||||
# include <variant>
|
||||
# define PYBIND11_HAS_OPTIONAL 1
|
||||
# define PYBIND11_HAS_VARIANT 1
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
|
Loading…
Reference in New Issue
Block a user