Skip to content

wil::reg::set_value doesn't work with std::wstring values #624

@Brainy0207

Description

@Brainy0207

When you try to call wil::reg::set_value with an std::wstring argument you get a compiler error.

e.g.:

std::wstring my_value = L"Hello";
wil::reg::set_value(HKEY_CURRENT_USER, L"Software\\MyApp", L"MyValue", my_value);

results in:

static_assert failed: 'Unsupported type for set_value_type'

The issue seems to be that reg_view_t::set_value deduces the argument type as const R& value, which will always be the non-const version:

template <typename R>
typename err_policy::result set_value(
_In_opt_ PCWSTR subkey, _In_opt_ PCWSTR value_name, const R& value, DWORD type = reg_value_type_info::set_value_type<R>()) const
{
return set_value_with_type(subkey, value_name, value, type);
}

It then passes R to reg_value_type_info::set_value_type<R>, but this expects the const version:

template <>
constexpr DWORD set_value_type<const ::std::wstring>() WI_NOEXCEPT
{
return REG_SZ;
}

This probably means that all other smart string variants listed there are also affected.

I think the best approach to fix this would be to switch all the affected set_value_type specializations to non-const.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions