diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 8d0fd5d9..67397c4e 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -995,9 +995,11 @@ public: } bool py_err = py_value == (py_type) -1 && PyErr_Occurred(); + + // Protect std::numeric_limits::min/max with parentheses if (py_err || (std::is_integral::value && sizeof(py_type) != sizeof(T) && - (py_value < (py_type) std::numeric_limits::min() || - py_value > (py_type) std::numeric_limits::max()))) { + (py_value < (py_type) (std::numeric_limits::min)() || + py_value > (py_type) (std::numeric_limits::max)()))) { bool type_error = py_err && PyErr_ExceptionMatches( #if PY_VERSION_HEX < 0x03000000 && !defined(PYPY_VERSION) PyExc_SystemError diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 300c2b23..a5b47c95 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -113,10 +113,6 @@ #include #include -#if defined(_WIN32) && (defined(min) || defined(max)) -# error Macro clash with min and max -- define NOMINMAX when compiling your program on Windows -#endif - #if defined(isalnum) # undef isalnum # undef isalpha diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 68e5757e..fbd971cf 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -495,7 +495,7 @@ protected: function_call call(func, parent); - size_t args_to_copy = std::min(pos_args, n_args_in); + size_t args_to_copy = (std::min)(pos_args, n_args_in); // Protect std::min with parentheses size_t args_copied = 0; // 0. Inject new-style `self` argument