From 449eb84acdb0ed27261da9a8b42daa34593abf62 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 18 Jul 2022 09:55:15 -0700 Subject: [PATCH] Using no-destructor idiom to side-step overzealous MINGW warning. --- tests/test_builtin_casters.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_builtin_casters.cpp b/tests/test_builtin_casters.cpp index 6529f47d0..01f06f0b7 100644 --- a/tests/test_builtin_casters.cpp +++ b/tests/test_builtin_casters.cpp @@ -266,9 +266,16 @@ TEST_SUBMODULE(builtin_casters, m) { }); m.def("lvalue_nested", []() -> const decltype(lvnested) & { return lvnested; }); - static std::pair int_string_pair{2, "items"}; m.def( - "int_string_pair", []() { return &int_string_pair; }, py::return_value_policy::reference); + "int_string_pair", + []() { + // Using no-destructor idiom to side-step overzealous MINGW GNU 12.1.0 + // 'void operator delete(void*)' called on unallocated object 'int_string_pair' + // warning (observed with windows-latest mingw32, mingw64 @ 2022-07-18). + static auto *int_string_pair = new std::pair{2, "items"}; + return int_string_pair; + }, + py::return_value_policy::reference); // test_builtins_cast_return_none m.def("return_none_string", []() -> std::string * { return nullptr; });