From 74c0348af8d82c1297a825f38f1684622952c37a Mon Sep 17 00:00:00 2001 From: GuyBrush Date: Tue, 19 Aug 2025 15:55:51 +0200 Subject: [PATCH 1/2] test: check several com_ptr call scenarios Signed-off-by: GuyBrush --- test/old_tests/UnitTests/com_ptr.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/old_tests/UnitTests/com_ptr.cpp b/test/old_tests/UnitTests/com_ptr.cpp index 5a5c8bcc4..57cf69583 100644 --- a/test/old_tests/UnitTests/com_ptr.cpp +++ b/test/old_tests/UnitTests/com_ptr.cpp @@ -385,3 +385,27 @@ TEST_CASE("com_ptr, compare") REQUIRE(!(nullptr != c)); REQUIRE(!(c != nullptr)); } + +TEST_CASE("com_ptr, calls") +{ + hstring test_string; + + // here com_ptr::type == Stringable + const wchar_t * grettings = L"Hello world!"; + com_ptr impl = make_self(grettings); + + // -> calls the projection + REQUIRE_NOTHROW(test_string = impl->ToString()); + REQUIRE(grettings == test_string); + + // here com_ptr::type == abi_t + com_ptr str(detach_abi(impl.as()), take_ownership_from_abi); + + // -> calls the abi + REQUIRE(0 == str->ToString(put_abi(test_string))); + REQUIRE(grettings == test_string); + + // * calls the projection + REQUIRE_NOTHROW(test_string = (*str).ToString()); + REQUIRE(grettings == test_string); +} From 76cdf0bf19442a907334a5f32469cf9c7cce1cb5 Mon Sep 17 00:00:00 2001 From: GuyBrush Date: Wed, 20 Aug 2025 00:49:55 +0200 Subject: [PATCH 2/2] fix: com_ptr missing a proper cast Signed-off-by: GuyBrush --- strings/base_com_ptr.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/strings/base_com_ptr.h b/strings/base_com_ptr.h index 14a9a0851..4bf41f7a4 100644 --- a/strings/base_com_ptr.h +++ b/strings/base_com_ptr.h @@ -112,7 +112,10 @@ WINRT_EXPORT namespace winrt T& operator*() const noexcept { - return *m_ptr; + if constexpr (std::is_same_v) + return *const_cast(m_ptr); + else + return *reinterpret_cast(const_cast(this)); } type* get() const noexcept