在 2025-02-28 02:35, Jøger Hansegård via Mingw-w64-public 写道:
+ template <class T, class U> + bool operator!=(const ComPtr<T> &a, const ComPtr<U> &b) throw() + { + static_assert(__is_base_of(T, U) || __is_base_of(U, T));
Static assertion without a message is a C++17 feature; this can cause errors in C++11 code. How about the attached patch? -- Best regards, LIU Hao
From 7e012ebde2c47eeceae9d0b3353efdff3b5c22bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8ger=20Hanseg=C3=A5rd?= <joger.hanseg...@qt.io> Date: Thu, 27 Feb 2025 17:12:09 +0100 Subject: [PATCH] Add missing comparison operators for Microsoft::WRL::ComPtr The current MinGW implementation of Microsoft::WRL::ComPtr does not have comparison operators. Attempting to compare two ComPtr instances will implicitly convert the ComPtr to bool, and comparison is performed against the resulting two bool values. This means that any two non-null ComPtr instances compare equal. This patch fixes this issue by adding the missing comparison operators. Signed-off-by: LIU Hao <lh_mo...@126.com> --- mingw-w64-headers/include/wrl/client.h | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/mingw-w64-headers/include/wrl/client.h b/mingw-w64-headers/include/wrl/client.h index aeb886ea8..b258a42ed 100644 --- a/mingw-w64-headers/include/wrl/client.h +++ b/mingw-w64-headers/include/wrl/client.h @@ -263,6 +263,51 @@ namespace Microsoft { return tmp->Release(); } }; + + template <class T, class U> + bool operator==(const ComPtr<T> &a, const ComPtr<U> &b) throw() + { + static_assert(__is_base_of(T, U) || __is_base_of(U, T)); + return a.Get() == b.Get(); + } + + template <class T> + bool operator==(const ComPtr<T> &a, std::nullptr_t) throw() + { + return a.Get() == nullptr; + } + + template <class T> + bool operator==(std::nullptr_t, const ComPtr<T> &a) throw() + { + return a.Get() == nullptr; + } + + template <class T, class U> + bool operator!=(const ComPtr<T> &a, const ComPtr<U> &b) throw() + { + static_assert(__is_base_of(T, U) || __is_base_of(U, T), "Type incompatible"); + return a.Get() != b.Get(); + } + + template <class T> + bool operator!=(const ComPtr<T> &a, std::nullptr_t) throw() + { + return a.Get() != nullptr; + } + + template <class T> + bool operator!=(std::nullptr_t, const ComPtr<T> &a) throw() + { + return a.Get() != nullptr; + } + + template <class T, class U> + bool operator<(const ComPtr<T> &a, const ComPtr<U> &b) throw() + { + static_assert(__is_base_of(T, U) || __is_base_of(U, T), "Type incompatible"); + return a.Get() < b.Get(); + } } } -- 2.48.1
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public