From a3bdd9da0866c61c8c532afeee584683adc1b890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Fri, 9 Jan 2026 11:07:54 +0100 Subject: [PATCH 1/2] fix: Fixes compilation failure with MSVC 17.12 (v14.44) and C++20: '_BACKUP_ITERATOR_DEBUG_LEVEL' undeclared when including span header from STL. --- include/pybind11/pybind11.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index c457e149c1..72ba78bed5 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -9,6 +9,14 @@ */ #pragma once + +// See Issue #5956. This fixes compilation failure with MSVC 17.12 (v14.44) and C++20: '_BACKUP_ITERATOR_DEBUG_LEVEL' undeclared when including span header from STL. +#if defined(_MSC_VER) +#ifndef _BACKUP_ITERATOR_DEBUG_LEVEL +#define _BACKUP_ITERATOR_DEBUG_LEVEL 0 +#endif +#endif + #include "detail/class.h" #include "detail/dynamic_raw_ptr_cast_if_possible.h" #include "detail/exception_translation.h" From c450c85937b0c2987e4aa140ce1202b061765938 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Jan 2026 10:15:07 +0000 Subject: [PATCH 2/2] style: pre-commit fixes --- include/pybind11/pybind11.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 72ba78bed5..bc9c2dd1f8 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -10,11 +10,12 @@ #pragma once -// See Issue #5956. This fixes compilation failure with MSVC 17.12 (v14.44) and C++20: '_BACKUP_ITERATOR_DEBUG_LEVEL' undeclared when including span header from STL. +// See Issue #5956. This fixes compilation failure with MSVC 17.12 (v14.44) and C++20: +// '_BACKUP_ITERATOR_DEBUG_LEVEL' undeclared when including span header from STL. #if defined(_MSC_VER) -#ifndef _BACKUP_ITERATOR_DEBUG_LEVEL -#define _BACKUP_ITERATOR_DEBUG_LEVEL 0 -#endif +# ifndef _BACKUP_ITERATOR_DEBUG_LEVEL +# define _BACKUP_ITERATOR_DEBUG_LEVEL 0 +# endif #endif #include "detail/class.h"