File onnxruntime-pybind11_state-ignore-unintialized-warnings.patch of Package onnxruntime

From: ingyukoh <ingyukoh2@gmail.com>
Date: Thu, 12 Feb 2026 16:38:22 +0900
Subject: [PATCH] Fix pybind11 3.0 build compatibility

Pybind11 3.0+ triggers false positive uninitialized variable warnings
in some compilers (GCC). With -Werror enabled, this causes build failure.

Add -Wno-maybe-uninitialized flag when building onnxruntime_pybind11_state
to suppress these false positives and allow building with pybind11 3.0.

Fixes #25681
---
 cmake/onnxruntime_python.cmake | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake
index 49a87833a7e65..8065bf01b46eb 100644
--- a/cmake/onnxruntime_python.cmake
+++ b/cmake/onnxruntime_python.cmake
@@ -94,6 +94,14 @@ if(HAS_CAST_FUNCTION_TYPE)
   target_compile_options(onnxruntime_pybind11_state PRIVATE "-Wno-cast-function-type")
 endif()
 
+# Pybind11 3.0+ may trigger false positive uninitialized variable warnings in some compilers.
+# Suppress these warnings to allow building with pybind11 3.0.
+include(CheckCXXCompilerFlag)
+check_cxx_compiler_flag("-Wno-maybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
+if(HAS_MAYBE_UNINITIALIZED)
+  target_compile_options(onnxruntime_pybind11_state PRIVATE "-Wno-maybe-uninitialized")
+endif()
+
 # We export symbols using linker and the compiler does not know anything about it
 # There is a problem with classes that have pybind types as members.
 # See https://pybind11.readthedocs.io/en/stable/faq.html#someclass-declared-with-greater-visibility-than-the-type-of-its-field-someclass-member-wattributes
openSUSE Build Service is sponsored by