Fix set_value template deduction for smart string types#633
Draft
benhillis wants to merge 3 commits intomicrosoft:masterfrom
Draft
Fix set_value template deduction for smart string types#633benhillis wants to merge 3 commits intomicrosoft:masterfrom
benhillis wants to merge 3 commits intomicrosoft:masterfrom
Conversation
The set_value_type<> specializations for std::wstring, BSTR, unique_bstr, shared_bstr, unique_cotaskmem_string, and shared_cotaskmem_string incorrectly used const-qualified template parameters (e.g. set_value_type<const std::wstring>). Since reg_view_t::set_value deduces R from 'const R& value', the template parameter R is always the non-const type. This caused a static_assert failure when calling set_value with any of these types. Remove the const qualifier from all six affected specializations so the deduced type matches the specialization. Fixes microsoft#624
dunhor
reviewed
Apr 21, 2026
dunhor
approved these changes
Apr 21, 2026
Replace function template specializations with a set_value_type_t struct template approach. The set_value_type<T>() wrapper function now applies wistd::remove_cv_t<T> internally, so callers never need to worry about cv-qualification of the template parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dunhor
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
set_value_type<>specializations forstd::wstring,BSTR,unique_bstr,shared_bstr,unique_cotaskmem_string, andshared_cotaskmem_stringincorrectly used const-qualified template parameters (e.g.set_value_type<const std::wstring>).Since
reg_view_t::set_valuededucesRfromconst R& value, the template parameterRis always the non-const type. This caused astatic_assertfailure (Unsupported type for set_value_type) when callingset_valuewith any of these types:\\cpp
std::wstring value{L"Hello"};
wil::reg::set_value(hkey, L"MyValue", value); // static_assert failure
\\
The fix removes the
constqualifier from all six affected specializations so the deduced type matches.Tests added for
std::wstringlvalues (non-const, const, and empty) with both opened-key and string-key overloads.Fixes #624