From f2d7e57d059b246d1c0537b81c20857c07da5f95 Mon Sep 17 00:00:00 2001 From: Tobias Leibner <7058290+tobiasleibner@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:58:58 +0200 Subject: [PATCH 1/2] Fix compiler detection with clang-cl --- include/pybind11/detail/pybind11_namespace_macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/pybind11_namespace_macros.h b/include/pybind11/detail/pybind11_namespace_macros.h index bd18c8c0a8..800c6ddf27 100644 --- a/include/pybind11/detail/pybind11_namespace_macros.h +++ b/include/pybind11/detail/pybind11_namespace_macros.h @@ -16,7 +16,7 @@ // possible using these macros. Please also be sure to push/pop with the pybind11 macros. Please // only use compiler specifics if you need to check specific versions, e.g. Apple Clang vs. vanilla // Clang. -#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(__clang__) // clang-cl also defines _MSC_VER # define PYBIND11_COMPILER_MSVC # define PYBIND11_PRAGMA(...) __pragma(__VA_ARGS__) # define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning(push)) From 2d86393366603a89cd1861f7551ab7ef49b474b3 Mon Sep 17 00:00:00 2001 From: Tobias Leibner <7058290+tobiasleibner@users.noreply.github.com> Date: Tue, 26 Aug 2025 08:48:38 +0200 Subject: [PATCH 2/2] Follow review suggestion --- include/pybind11/detail/pybind11_namespace_macros.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/pybind11/detail/pybind11_namespace_macros.h b/include/pybind11/detail/pybind11_namespace_macros.h index 800c6ddf27..6f74bf85c7 100644 --- a/include/pybind11/detail/pybind11_namespace_macros.h +++ b/include/pybind11/detail/pybind11_namespace_macros.h @@ -16,12 +16,7 @@ // possible using these macros. Please also be sure to push/pop with the pybind11 macros. Please // only use compiler specifics if you need to check specific versions, e.g. Apple Clang vs. vanilla // Clang. -#if defined(_MSC_VER) && !defined(__clang__) // clang-cl also defines _MSC_VER -# define PYBIND11_COMPILER_MSVC -# define PYBIND11_PRAGMA(...) __pragma(__VA_ARGS__) -# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning(push)) -# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning(pop)) -#elif defined(__INTEL_COMPILER) +#if defined(__INTEL_COMPILER) # define PYBIND11_COMPILER_INTEL # define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__) # define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning push) @@ -36,6 +31,11 @@ # define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__) # define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(GCC diagnostic push) # define PYBIND11_WARNING_POP PYBIND11_PRAGMA(GCC diagnostic pop) +#elif defined(_MSC_VER) // Must be after the clang branch because clang-cl also defines _MSC_VER +# define PYBIND11_COMPILER_MSVC +# define PYBIND11_PRAGMA(...) __pragma(__VA_ARGS__) +# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning(push)) +# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning(pop)) #endif #ifdef PYBIND11_COMPILER_MSVC