C:\Temp>type repro.cpp
#include <coroutine>
#include <unordered_set>
int main()
{
std::unordered_set<std::coroutine_handle<>> set;
set.insert(std::coroutine_handle{});
}
C:\temp>cl /EHsc /W4 /WX /std:c++latest .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29333 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.
repro.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\include\xhash(131): error C3848: expression having type 'const _Hasher' would lose some const-volatile qualifiers in order to call 'size_t std::hash<std::coroutine_handle<void>>::operator ()(const std::coroutine_handle<void> &) noexcept'
with
[
_Hasher=std::hash<std::coroutine_handle<void>>
]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\include\xhash(155): note: see reference to variable template 'const bool _Nothrow_hash<std::hash<std::coroutine_handle<void> >,std::coroutine_handle<void> >' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\include\xhash(155): note: while compiling class template member function 'size_t std::_Uhash_compare<_Kty,_Hasher,_Keyeq>::operator ()<_Key>(const _Keyty &) noexcept(<expr>) const'
with
[
_Kty=std::coroutine_handle<void>,
_Hasher=std::hash<std::coroutine_handle<void>>,
_Keyeq=std::equal_to<std::coroutine_handle<void>>,
_Key=std::coroutine_handle<void>,
_Keyty=std::coroutine_handle<void>
]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\include\xhash(1068): note: see reference to function template instantiation 'std::pair<std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>,bool> std::_Hash<std::_Uset_traits<_Kty,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::emplace<std::coroutine_handle<void>>(std::coroutine_handle<void> &&)' being compiled
with
[
_Ty=std::coroutine_handle<void>,
_Kty=std::coroutine_handle<void>,
_Hasher=std::hash<std::coroutine_handle<void>>,
_Keyeq=std::equal_to<std::coroutine_handle<void>>,
_Alloc=std::allocator<std::coroutine_handle<void>>
]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\include\xhash(1068): note: see reference to function template instantiation 'std::pair<std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>,bool> std::_Hash<std::_Uset_traits<_Kty,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::emplace<std::coroutine_handle<void>>(std::coroutine_handle<void> &&)' being compiled
with
[
_Ty=std::coroutine_handle<void>,
_Kty=std::coroutine_handle<void>,
_Hasher=std::hash<std::coroutine_handle<void>>,
_Keyeq=std::equal_to<std::coroutine_handle<void>>,
_Alloc=std::allocator<std::coroutine_handle<void>>
]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\include\xhash(1067): note: while compiling class template member function 'std::pair<std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>,bool> std::_Hash<std::_Uset_traits<_Kty,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::insert(std::coroutine_handle<void> &&)'
with
[
_Ty=std::coroutine_handle<void>,
_Kty=std::coroutine_handle<void>,
_Hasher=std::hash<std::coroutine_handle<void>>,
_Keyeq=std::equal_to<std::coroutine_handle<void>>,
_Alloc=std::allocator<std::coroutine_handle<void>>
]
.\repro.cpp(7): note: see reference to function template instantiation 'std::pair<std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>,bool> std::_Hash<std::_Uset_traits<_Kty,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::insert(std::coroutine_handle<void> &&)' being compiled
with
[
_Ty=std::coroutine_handle<void>,
_Kty=std::coroutine_handle<void>,
_Hasher=std::hash<std::coroutine_handle<void>>,
_Keyeq=std::equal_to<std::coroutine_handle<void>>,
_Alloc=std::allocator<std::coroutine_handle<void>>
]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\include\unordered_set(65): note: see reference to class template instantiation 'std::_Hash<std::_Uset_traits<_Kty,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>' being compiled
with
[
_Kty=std::coroutine_handle<void>,
_Hasher=std::hash<std::coroutine_handle<void>>,
_Keyeq=std::equal_to<std::coroutine_handle<void>>,
_Alloc=std::allocator<std::coroutine_handle<void>>
]
.\repro.cpp(6): note: see reference to class template instantiation 'std::unordered_set<std::coroutine_handle<void>,std::hash<std::coroutine_handle<void>>,std::equal_to<std::coroutine_handle<void>>,std::allocator<std::coroutine_handle<void>>>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\include\xhash(130): error C2056: illegal expression
Describe the bug
The operator() in the coroutine_handle specialization of std::hash is not marked const, so compilation fails when hashing containers try to use it.
Command-line test case
Expected behavior
No warnings/errors about const qualifications during compilation.
STL version
Microsoft Visual Studio Community 2019 Preview Version 16.8.0 Preview 6.0