From f1b44a051a39a01ef83c90f7d5485e38c40eac15 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 4 Nov 2016 09:49:37 -0400 Subject: [PATCH] requires -std=c++17 (#479) There are now more places than just descr.h that make use of these. The new macro isn't quite the same: the old one only tested for a couple features, while the new one checks for the __cplusplus version (but doesn't even try to enable C++14 for MSVC/ICC). g++ 7 adds , but including it in C++14 mode isn't allowed (just as including isn't allowed in C++11 mode). (This wasn't triggered in g++-6 because it doesn't provide yet.) --- include/pybind11/common.h | 14 +++++++++++++- include/pybind11/descr.h | 12 ------------ include/pybind11/stl.h | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 62198c341..e684b187e 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -16,6 +16,18 @@ # 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 +# if __cplusplus > 201402L /* Temporary: should be updated to >= the final C++17 value once known */ +# define PYBIND11_CPP17 +# endif +# endif +#endif + #if !defined(PYBIND11_EXPORT) # if defined(WIN32) || defined(_WIN32) # define PYBIND11_EXPORT __declspec(dllexport) @@ -30,7 +42,7 @@ # define PYBIND11_NOINLINE __attribute__ ((noinline)) #endif -#if __cplusplus > 201103L +#if defined(PYBIND11_CPP14) # define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]] #elif defined(__clang__) # define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason))) diff --git a/include/pybind11/descr.h b/include/pybind11/descr.h index f8a349b1a..a9a1f67aa 100644 --- a/include/pybind11/descr.h +++ b/include/pybind11/descr.h @@ -15,18 +15,6 @@ NAMESPACE_BEGIN(pybind11) NAMESPACE_BEGIN(detail) -#if defined(__INTEL_COMPILER) -/* C++14 features not supported for now */ -#elif defined(__clang__) -# if __has_feature(cxx_return_type_deduction) && __has_feature(cxx_relaxed_constexpr) -# define PYBIND11_CPP14 -# endif -#elif defined(__GNUG__) -# if __cpp_constexpr >= 201304 && __cpp_decltype_auto >= 201304 -# define PYBIND11_CPP14 -# endif -#endif - #if defined(PYBIND11_CPP14) /* Concatenate type signatures at compile time using C++14 */ template class descr { diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index 4da67df2b..ae0b3affb 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -22,14 +22,14 @@ #pragma warning(disable: 4127) // warning C4127: Conditional expression is constant #endif -#if defined(PYBIND11_CPP14) && defined(__has_include) -// std::optional -# if __has_include() +#ifdef __has_include +// std::optional (but including it in c++14 mode isn't allowed) +# if defined(PYBIND11_CPP17) && __has_include() # include # define PYBIND11_HAS_OPTIONAL 1 # endif -// std::experimental::optional -# if __has_include() +// std::experimental::optional (but not allowed in c++11 mode) +# if defined(PYBIND11_CPP14) && __has_include() # include # if __cpp_lib_experimental_optional // just in case # define PYBIND11_HAS_EXP_OPTIONAL 1