Closed
Description
Version
No response
Summary
PREFast scanning of a generated cppwinrt file for WASDK sample app /Samples/ResourceManagement/cpp-winui/winui_desktop_packaged_app_cpp/Generated Files/winrt/base.h on the https://github.com/microsoft/WindowsAppSDK-Samples repository hit warning: "'Temp_value_#22808' holds a value that must be examined."
The right fix for this issue appears to be centrally in cppwinrt generated code, instead of the individual sample apps that leverage cppwinrt.
Reproducible example
The following code in Base.h seems to be what the warning is referring to:
impl::IWeakReferenceSource* make_weak_ref() noexcept
{
if constexpr (is_weak_ref_source::value)
{
uintptr_t count_or_pointer = m_references.load(std::memory_order_relaxed);
if (is_weak_ref(count_or_pointer))
{
return decode_weak_ref(count_or_pointer)->get_source();
}
com_ptr<weak_ref_t> weak_ref;
*weak_ref.put() = new (std::nothrow) weak_ref_t(get_unknown(), static_cast<uint32_t>(count_or_pointer));
if (!weak_ref)
{
return nullptr;
}
uintptr_t const encoding = encode_weak_ref(weak_ref.get());
while (true)
{
if (m_references.compare_exchange_weak(count_or_pointer, encoding, std::memory_order_acq_rel, std::memory_order_relaxed))
{
impl::IWeakReferenceSource* result = weak_ref->get_source();
detach_abi(weak_ref);
return result;
}
if (is_weak_ref(count_or_pointer))
{
return decode_weak_ref(count_or_pointer)->get_source();
}
weak_ref->set_strong(static_cast<uint32_t>(count_or_pointer));
}
}
else
{
static_assert(is_weak_ref_source::value, "Weak references are not supported because no_weak_ref was specified.");
return nullptr;
}
}
Expected behavior
No response
Actual behavior
No response
Additional comments
No response
Metadata
Metadata
Assignees
Labels
No labels