Skip to content

Commit f816245

Browse files
authored
Fix unbox_value_or with explicit type or implicit hstring (#656)
1 parent 297365e commit f816245

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

strings/base_reference_produce.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ WINRT_EXPORT namespace winrt
318318
}
319319
}
320320

321-
template <typename T>
321+
template <typename T = hstring, std::enable_if_t<std::is_same_v<T, hstring>, int> = 0>
322322
hstring unbox_value_or(Windows::Foundation::IInspectable const& value, param::hstring const& default_value)
323323
{
324324
if (value)

test/old_tests/UnitTests/Boxing2.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,10 @@ TEST_CASE("Boxing")
214214
REQUIRE(unbox_value_or<UnsignedEnum>(box_value(static_cast<int32_t>(UnsignedEnum::Second)), UnsignedEnum::First) == UnsignedEnum::First);
215215
REQUIRE(unbox_value_or<UnsignedEnum>(box_value(static_cast<uint16_t>(UnsignedEnum::Second)), UnsignedEnum::First) == UnsignedEnum::First);
216216
}
217+
218+
{
219+
// Test some cases where the compiler has to choose between multiple overloads.
220+
REQUIRE(unbox_value_or<IInspectable>(nullptr, {}) == IInspectable{});
221+
REQUIRE(unbox_value_or(nullptr, hstring{}) == hstring{});
222+
}
217223
}

0 commit comments

Comments
 (0)