From fa61b54cd275a520da971fc8feb6388abd9dc332 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Wed, 7 Jan 2026 20:34:18 +0800 Subject: [PATCH 1/4] Appease MSVC Warning C4866: compiler may not enforce left-to-right evaluation order --- include/pybind11/pybind11.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 45e8e46f89..e3da531d08 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1081,7 +1081,10 @@ class cpp_function : public function { 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]; + // Appease MSVC C4866: compiler may not enforce left-to-right + // evaluation order + const 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); From a3a2e4d7c39aa88ece538c0ee975fcb37d6c0bb3 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Wed, 7 Jan 2026 21:02:25 +0800 Subject: [PATCH 2/4] Remove const qualifier --- include/pybind11/pybind11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index e3da531d08..9b66a169f2 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1083,7 +1083,7 @@ class cpp_function : public function { if (!used_kwargs[i]) { // Appease MSVC C4866: compiler may not enforce left-to-right // evaluation order - const PyObject *const arg_in_arr = args_in_arr[n_args_in + i]; + PyObject *const arg_in_arr = args_in_arr[n_args_in + i]; kwargs[PyTuple_GET_ITEM(kwnames_in, i)] = arg_in_arr; } } From 1ebe0e2956cdd50b503e26ce7be40823bb3d1ae9 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 7 Jan 2026 11:04:09 -0800 Subject: [PATCH 3/4] 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. --- include/pybind11/pybind11.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 9b66a169f2..c457e149c1 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1081,8 +1081,8 @@ class cpp_function : public function { dict kwargs; for (size_t i = 0; i < used_kwargs.size(); ++i) { if (!used_kwargs[i]) { - // Appease MSVC C4866: compiler may not enforce left-to-right - // evaluation order + // 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; } From f16de66e67f2d2580b07f90ebd0fcd6213f8a0f0 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 7 Jan 2026 11:08:38 -0800 Subject: [PATCH 4/4] 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 --- .pre-commit-config.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9cb3f22dfa..1271c2afe5 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: []