4747// or newer.
4848# if _MSVC_LANG >= 201402L
4949# define PYBIND11_CPP14
50- # if _MSVC_LANG > 201402L && _MSC_VER >= 1910
50+ # if _MSVC_LANG > 201402L
5151# define PYBIND11_CPP17
5252# if _MSVC_LANG >= 202002L
5353# define PYBIND11_CPP20
8181# error pybind11 requires gcc 4.8 or newer
8282# endif
8383#elif defined(_MSC_VER)
84- // Pybind hits various compiler bugs in 2015u2 and earlier, and also makes use of some stl features
85- // (e.g. std::negation) added in 2015u3:
86- # if _MSC_FULL_VER < 190024210
87- # error pybind11 requires MSVC 2015 update 3 or newer
84+ # if _MSC_VER < 1910
85+ # error pybind11 2.10+ requires MSVC 2017 or newer
8886# endif
8987#endif
9088
149147
150148/* Don't let Python.h #define (v)snprintf as macro because they are implemented
151149 properly in Visual Studio since 2015. */
152- #if defined(_MSC_VER) && _MSC_VER >= 1900
150+ #if defined(_MSC_VER)
153151# define HAVE_SNPRINTF 1
154152#endif
155153
@@ -561,7 +559,7 @@ static_assert(std::is_standard_layout<instance>::value,
561559 " Internal error: `pybind11::detail::instance` is not standard layout!" );
562560
563561// / from __cpp_future__ import (convenient aliases from C++14/17)
564- #if defined(PYBIND11_CPP14) && (!defined(_MSC_VER) || _MSC_VER >= 1910)
562+ #if defined(PYBIND11_CPP14)
565563using std::conditional_t ;
566564using std::enable_if_t ;
567565using std::remove_cv_t ;
@@ -824,10 +822,10 @@ struct is_template_base_of_impl {
824822// / Check if a template is the base of a type. For example:
825823// / `is_template_base_of<Base, T>` is true if `struct T : Base<U> {}` where U can be anything
826824template <template <typename ...> class Base , typename T>
827- #if !defined(_MSC_VER)
825+ #if defined(PYBIND11_CPP20) || !defined(_MSC_VER) // Sadly, all MSVC versions incl. 2022 need this.
828826using is_template_base_of
829827 = decltype (is_template_base_of_impl<Base>::check((intrinsic_t <T> *) nullptr ));
830- #else // MSVC2015 has trouble with decltype in template aliases
828+ #else
831829struct is_template_base_of
832830 : decltype (is_template_base_of_impl<Base>::check((intrinsic_t <T> *) nullptr )) {
833831};
@@ -1002,9 +1000,6 @@ struct nodelete {
10021000PYBIND11_NAMESPACE_BEGIN (detail)
10031001template <typename... Args>
10041002struct overload_cast_impl {
1005- // NOLINTNEXTLINE(modernize-use-equals-default): MSVC 2015 needs this
1006- constexpr overload_cast_impl () {}
1007-
10081003 template <typename Return>
10091004 constexpr auto operator ()(Return (*pf)(Args...)) const noexcept -> decltype (pf) {
10101005 return pf;
@@ -1031,8 +1026,12 @@ PYBIND11_NAMESPACE_END(detail)
10311026// / - regular: static_cast<Return (Class::*)(Arg0, Arg1, Arg2)>(&Class::func)
10321027// / - sweet: overload_cast<Arg0, Arg1, Arg2>(&Class::func)
10331028template <typename ... Args>
1029+ # if (defined(_MSC_VER) && _MSC_VER < 1920) /* MSVC 2017 */ \
1030+ || (defined (__clang__) && __clang_major__ == 5 )
10341031static constexpr detail::overload_cast_impl<Args...> overload_cast = {};
1035- // MSVC 2015 only accepts this particular initialization syntax for this variable template.
1032+ # else
1033+ static constexpr detail::overload_cast_impl<Args...> overload_cast;
1034+ # endif
10361035#endif
10371036
10381037// / Const member function selector for overload_cast
@@ -1118,7 +1117,7 @@ try_get_shared_from_this(std::enable_shared_from_this<T> *holder_value_ptr) {
11181117
11191118// For silencing "unused" compiler warnings in special situations.
11201119template <typename ... Args>
1121- #if defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER < 1920 // MSVC 2017
1120+ #if defined(_MSC_VER) && _MSC_VER < 1920 // MSVC 2017
11221121constexpr
11231122#endif
11241123 inline void
0 commit comments