microsoft / microsoft/wil

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

Closed
#624 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
3k
Forks
300
Avg merge
19h 12m
Merged PRs (30d)
1

Description

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:

https://github.com/microsoft/wil/blob/3ecba603d9789435b0661be7b7154d45c195ef98/include/wil/registry_helpers.h#L1182-L1187

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

https://github.com/microsoft/wil/blob/3ecba603d9789435b0661be7b7154d45c195ef98/include/wil/registry_helpers.h#L1008-L1012

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in include/wil/registry_helpers.h, especially reg_view_t::set_value around lines 1182-1187 and the reg_value_type_info::set_value_type specializations around lines 1008-1012. Reproduce the shown std::wstring example, then verify that it and the other listed smart string variants are accepted without the unsupported-type compiler error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.