<optional> 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 <optional>, but including it in C++14 mode isn't allowed
(just as including <experimental/optional> isn't allowed in C++11 mode).
(This wasn't triggered in g++-6 because it doesn't provide <optional>
yet.)
This commit is contained in:
Jason Rhinelander 2016-11-04 09:49:37 -04:00 committed by Wenzel Jakob
parent dc0b4bd2c9
commit f1b44a051a
3 changed files with 18 additions and 18 deletions

View File

@ -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)))

View File

@ -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 <size_t Size1, size_t Size2> class descr {

View File

@ -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(<optional>)
#ifdef __has_include
// std::optional (but including it in c++14 mode isn't allowed)
# if defined(PYBIND11_CPP17) && __has_include(<optional>)
# include <optional>
# define PYBIND11_HAS_OPTIONAL 1
# endif
// std::experimental::optional
# if __has_include(<experimental/optional>)
// std::experimental::optional (but not allowed in c++11 mode)
# if defined(PYBIND11_CPP14) && __has_include(<experimental/optional>)
# include <experimental/optional>
# if __cpp_lib_experimental_optional // just in case
# define PYBIND11_HAS_EXP_OPTIONAL 1