From d36f5dd5a4ee012e7969617ff67c4fd816bdc927 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Thu, 8 Jan 2026 08:28:38 +0800 Subject: [PATCH] Appease MSVC Warning C4866: compiler may not enforce left-to-right evaluation order (#5953) * Appease MSVC Warning C4866: compiler may not enforce left-to-right evaluation order * Remove const qualifier * Reword comment to be self-explanatory without PR context The previous comment referenced the MSVC warning but didn't explain why the code is structured as two statements. The revised comment clarifies the intent: fetching the value first ensures well-defined evaluation order. * chore(deps): switch typos to mirror repo Switch from crate-ci/typos to adhtruong/mirrors-typos because pre-commit autoupdate confuses tags in the upstream repo, selecting the mutable `v1` tag instead of pinned versions like `v1.41.0`. See https://github.com/crate-ci/typos/issues/390 --------- Co-authored-by: Ralf W. Grosse-Kunstleve --- .pre-commit-config.yaml | 6 ++++-- include/pybind11/pybind11.h | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9cb3f22df..1271c2afe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -119,8 +119,10 @@ repos: args: ["-x.codespell-ignore-lines", "-Lccompiler,intstruct"] # Also check spelling -- repo: https://github.com/crate-ci/typos - rev: v1 +# Use mirror because pre-commit autoupdate confuses tags in the upstream repo. +# See https://github.com/crate-ci/typos/issues/390 +- repo: https://github.com/adhtruong/mirrors-typos + rev: "v1.41.0" hooks: - id: typos args: [] diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 45e8e46f8..c457e149c 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1081,7 +1081,10 @@ protected: dict kwargs; for (size_t i = 0; i < used_kwargs.size(); ++i) { if (!used_kwargs[i]) { - kwargs[PyTuple_GET_ITEM(kwnames_in, i)] = args_in_arr[n_args_in + i]; + // Fetch value before indexing into kwargs to ensure well-defined + // evaluation order (MSVC C4866). + PyObject *const arg_in_arr = args_in_arr[n_args_in + i]; + kwargs[PyTuple_GET_ITEM(kwnames_in, i)] = arg_in_arr; } } call.args.push_back(kwargs);