You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compilation error with std::hash<gsl::not_null<std::shared_ptr<T>>> in GSL 4.2.0 #1209
error C2280: 'gsl::not_null_hash<gsl::not_null<std::shared_ptr<int>>,const T &,false>::not_null_hash(void)': attempting to reference a deleted function
error C2280: with
error C2280: [
error C2280: T=std::shared_ptr<int>
error C2280: ]
GSL-4.2.0\include\gsl\pointers(244,5):
see declaration of 'gsl::not_null_hash<gsl::not_null<std::shared_ptr<int>>,const T &,false>::not_null_hash'
with
[
T=std::shared_ptr<int>
]
GSL-4.2.0\include\gsl\pointers(244,5):
'gsl::not_null_hash<gsl::not_null<std::shared_ptr<int>>,const T &,false>::not_null_hash(void)': function was explicitly deleted
with
[
T=std::shared_ptr<int>
]
Expected behavior
The specialization of std::hash for gsl::not_null<std::shared_ptr<T>> should compile successfully.
Spec:
OS: Windows
Compiler: MSVC 17.13.6
C++ Version: C++20
Additional context
In the following template from <gsl/pointers>:
it might be necessary to apply std::remove_cv_t<std::remove_reference_t<...>> to the type U to properly deduce the underlying type and avoid issues with const/reference qualifiers.
it might be necessary to apply std::remove_cv_t<std::remove_reference_t<...>> to the type U to properly deduce the underlying type and avoid issues with const/reference qualifiers.
Yes, U was resolving to const std::shared_ptr<int> & instead of std::shared_ptr<int> which was causing further failures to the template instantiations for std::hash<T>. Your solution of applying the nested remove_* would have worked, but I think we can just use gsl::not_null<T>::element_type here instead.
Activity
carsonRadtke commentedon May 29, 2025
Thanks for reporting this issue! I'll investigate and post an update when I know more.
carsonRadtke commentedon Jun 2, 2025
Yes,
Uwas resolving toconst std::shared_ptr<int> &instead ofstd::shared_ptr<int>which was causing further failures to the template instantiations forstd::hash<T>. Your solution of applying the nestedremove_*would have worked, but I think we can just usegsl::not_null<T>::element_typehere instead.carsonRadtke commentedon Jun 2, 2025
Let's update the template for
not_null_hashto grabT::element_typeand use that to construct the hasher.