From e29b35bde1444d5c1d9fda76f6c58801276aad5a Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Tue, 6 May 2025 00:14:30 +0800 Subject: [PATCH] fix: handle MSVC warning C4866: compiler may not enforce left-to-right evaluation order --- include/pybind11/detail/function_record_pyobject.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/pybind11/detail/function_record_pyobject.h b/include/pybind11/detail/function_record_pyobject.h index 13895b96f2..82a574270d 100644 --- a/include/pybind11/detail/function_record_pyobject.h +++ b/include/pybind11/detail/function_record_pyobject.h @@ -13,6 +13,7 @@ #include "common.h" #include +#include PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(detail) @@ -188,9 +189,11 @@ inline PyObject *reduce_ex_impl(PyObject *self, PyObject *, PyObject *) { && PyModule_Check(rec->scope.ptr()) != 0) { object scope_module = get_scope_module(rec->scope); if (scope_module) { - return make_tuple(reinterpret_borrow(PyEval_GetBuiltins())["eval"], - make_tuple(str("__import__('importlib').import_module('") - + scope_module + str("')"))) + auto builtins = reinterpret_borrow(PyEval_GetBuiltins()); + auto builtins_eval = builtins["eval"]; + auto reconstruct_args = make_tuple(str("__import__('importlib').import_module('") + + scope_module + str("')")); + return make_tuple(std::move(builtins_eval), std::move(reconstruct_args)) .release() .ptr(); }