Fix set_value template deduction for smart string types#633
Draft
benhillis wants to merge 2 commits into
Draft
Conversation
dunhor
reviewed
Apr 21, 2026
dunhor
approved these changes
Apr 21, 2026
dunhor
approved these changes
Apr 23, 2026
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
851030a to
b2034ad
Compare
Per review feedback, convert the set_value_type function family into a set_value_type_t<T> trait struct with a constexpr DWORD value member, and make set_value_type<T>() a thin wrapper that applies wistd::remove_cv_t. This removes the need for callers to strip cv-qualifiers from the deduced type while keeping the type fully specializable for future use. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dunhor
approved these changes
Jun 11, 2026
Member
|
Feel free to publish as "ready for review" if this change is ready |
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