-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed as not planned
Labels
invalidResolved as invalid, i.e. not a bugResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Description
#include <unordered_map>
// #include <vector>
using namespace std;
int main() {
unordered_map<string, int> m;
m["test"]=0;
return 0;
}
doesn't compile. But it compiles with vector in #161946.
hash_memory.cc:8:4: error: no viable overloaded operator[] for type 'unordered_map<string, int>' (aka 'unordered_map<basic_string<char>, int>')
8 | m["test"]=0;
| ~^~~~~~~
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:1348:38: note: candidate function not viable: no known conversion from 'const char[5]' to 'const key_type' (aka 'const std::basic_string<char>') for 1st argument
1348 | _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k);
| ^ ~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:1350:38: note: candidate function not viable: no known conversion from 'const char[5]' to 'key_type' (aka 'std::basic_string<char>') for 1st argument
1350 | _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k);
| ^ ~~~~~~~~~~~~~~
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:653:111: error: call to implicitly-deleted default constructor of 'std::hash<std::basic_string<char>>'
653 | _LIBCPP_HIDE_FROM_ABI __unordered_map_hasher() _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) : _Hash() {}
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:1070:50: note: in instantiation of member function 'std::__unordered_map_hasher<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::hash<std::basic_string<char>>, std::equal_to<std::basic_string<char>>>::__unordered_map_hasher' requested here
1070 | inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() _NOEXCEPT_(
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:1008:25: note: in instantiation of member function 'std::__hash_table<std::__hash_value_type<std::basic_string<char>, int>, std::__unordered_map_hasher<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::hash<std::basic_string<char>>, std::equal_to<std::basic_string<char>>>, std::__unordered_map_equal<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::equal_to<std::basic_string<char>>, std::hash<std::basic_string<char>>>, std::allocator<std::pair<const std::basic_string<char>, int>>>::__hash_table' requested here
1008 | _LIBCPP_HIDE_FROM_ABI unordered_map() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
| ^
hash_memory.cc:7:30: note: in instantiation of member function 'std::unordered_map<std::basic_string<char>, int>::unordered_map' requested here
7 | unordered_map<string, int> m;
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__functional/hash.h:434:15: note: default constructor of 'hash<std::basic_string<char>>' is implicitly deleted because base class '__hash_impl<std::basic_string<char, std::char_traits<char>, std::allocator<char>>>' has a deleted default constructor
434 | struct hash : public __hash_impl<_Tp> {};
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__functional/hash.h:353:3: note: '__hash_impl' has been explicitly marked deleted here
353 | __hash_impl() = delete;
| ^
In file included from hash_memory.cc:1:
In file included from /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:592:
In file included from /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__functional/hash.h:26:
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__utility/pair.h:98:7: error: implicit instantiation of undefined template 'std::basic_string<char>'
98 | _T1 first;
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:139:23: note: in instantiation of template class 'std::pair<const std::basic_string<char>, int>' requested here
139 | __node_value_type __value_;
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:138:3: note: in instantiation of member class 'std::__hash_node<std::__hash_value_type<std::basic_string<char>, int>, void *>::(anonymous union at /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:138:3)' requested here
138 | union {
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:1204:65: note: in instantiation of template class 'std::__hash_node<std::__hash_value_type<std::basic_string<char>, int>, void *>' requested here
1204 | __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__get_value()));
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:1172:3: note: in instantiation of member function 'std::__hash_table<std::__hash_value_type<std::basic_string<char>, int>, std::__unordered_map_hasher<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::hash<std::basic_string<char>>, std::equal_to<std::basic_string<char>>>, std::__unordered_map_equal<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::equal_to<std::basic_string<char>>, std::hash<std::basic_string<char>>>, std::allocator<std::pair<const std::basic_string<char>, int>>>::__deallocate_node' requested here
1172 | __deallocate_node(__first_node_.__next_);
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:1008:25: note: in instantiation of member function 'std::__hash_table<std::__hash_value_type<std::basic_string<char>, int>, std::__unordered_map_hasher<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::hash<std::basic_string<char>>, std::equal_to<std::basic_string<char>>>, std::__unordered_map_equal<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::equal_to<std::basic_string<char>>, std::hash<std::basic_string<char>>>, std::allocator<std::pair<const std::basic_string<char>, int>>>::~__hash_table' requested here
1008 | _LIBCPP_HIDE_FROM_ABI unordered_map() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
| ^
hash_memory.cc:7:30: note: in instantiation of member function 'std::unordered_map<std::basic_string<char>, int>::unordered_map' requested here
7 | unordered_map<string, int> m;
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__fwd/string.h:43:7: note: template is declared here
43 | class basic_string;
| ^
In file included from hash_memory.cc:1:
In file included from /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:592:
In file included from /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__functional/hash.h:26:
In file included from /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__utility/pair.h:35:
In file included from /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__type_traits/is_replaceable.h:16:
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__type_traits/is_trivially_copyable.h:23:83: error: implicit instantiation of undefined template 'std::basic_string<char>'
23 | struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_copyable : integral_constant<bool, __is_trivially_copyable(_Tp)> {};
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__type_traits/is_trivially_relocatable.h:34:44: note: in instantiation of template class 'std::is_trivially_copyable<const std::basic_string<char>>' requested here
34 | struct __libcpp_is_trivially_relocatable : is_trivially_copyable<_Tp> {};
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__utility/pair.h:102:23: note: in instantiation of template class 'std::__libcpp_is_trivially_relocatable<const std::basic_string<char>>' requested here
102 | __conditional_t<__libcpp_is_trivially_relocatable<_T1>::value && __libcpp_is_trivially_relocatable<_T2>::value,
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:139:23: note: in instantiation of template class 'std::pair<const std::basic_string<char>, int>' requested here
139 | __node_value_type __value_;
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:138:3: note: in instantiation of member class 'std::__hash_node<std::__hash_value_type<std::basic_string<char>, int>, void *>::(anonymous union at /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:138:3)' requested here
138 | union {
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:1204:65: note: in instantiation of template class 'std::__hash_node<std::__hash_value_type<std::basic_string<char>, int>, void *>' requested here
1204 | __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__get_value()));
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:1172:3: note: in instantiation of member function 'std::__hash_table<std::__hash_value_type<std::basic_string<char>, int>, std::__unordered_map_hasher<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::hash<std::basic_string<char>>, std::equal_to<std::basic_string<char>>>, std::__unordered_map_equal<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::equal_to<std::basic_string<char>>, std::hash<std::basic_string<char>>>, std::allocator<std::pair<const std::basic_string<char>, int>>>::__deallocate_node' requested here
1172 | __deallocate_node(__first_node_.__next_);
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:1008:25: note: in instantiation of member function 'std::__hash_table<std::__hash_value_type<std::basic_string<char>, int>, std::__unordered_map_hasher<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::hash<std::basic_string<char>>, std::equal_to<std::basic_string<char>>>, std::__unordered_map_equal<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::equal_to<std::basic_string<char>>, std::hash<std::basic_string<char>>>, std::allocator<std::pair<const std::basic_string<char>, int>>>::~__hash_table' requested here
1008 | _LIBCPP_HIDE_FROM_ABI unordered_map() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
| ^
hash_memory.cc:7:30: note: in instantiation of member function 'std::unordered_map<std::basic_string<char>, int>::unordered_map' requested here
7 | unordered_map<string, int> m;
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__fwd/string.h:43:7: note: template is declared here
43 | class basic_string;
| ^
In file included from hash_memory.cc:1:
In file included from /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:595:
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:103:12: error: static_cast from 'pointer' (aka 'std::__hash_node_base<std::__hash_node<std::__hash_value_type<std::basic_string<char>, int>, void *> *> *') to '__node_pointer' (aka 'std::__hash_node<std::__hash_value_type<std::basic_string<char>, int>, void *> *'), which are not related by inheritance, is not allowed
103 | return static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(*this));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:1203:38: note: in instantiation of member function 'std::__hash_node_base<std::__hash_node<std::__hash_value_type<std::basic_string<char>, int>, void *> *>::__upcast' requested here
1203 | __node_pointer __real_np = __np->__upcast();
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:1172:3: note: in instantiation of member function 'std::__hash_table<std::__hash_value_type<std::basic_string<char>, int>, std::__unordered_map_hasher<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::hash<std::basic_string<char>>, std::equal_to<std::basic_string<char>>>, std::__unordered_map_equal<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::equal_to<std::basic_string<char>>, std::hash<std::basic_string<char>>>, std::allocator<std::pair<const std::basic_string<char>, int>>>::__deallocate_node' requested here
1172 | __deallocate_node(__first_node_.__next_);
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:1008:25: note: in instantiation of member function 'std::__hash_table<std::__hash_value_type<std::basic_string<char>, int>, std::__unordered_map_hasher<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::hash<std::basic_string<char>>, std::equal_to<std::basic_string<char>>>, std::__unordered_map_equal<std::basic_string<char>, std::pair<const std::basic_string<char>, int>, std::equal_to<std::basic_string<char>>, std::hash<std::basic_string<char>>>, std::allocator<std::pair<const std::basic_string<char>, int>>>::~__hash_table' requested here
1008 | _LIBCPP_HIDE_FROM_ABI unordered_map() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
| ^
hash_memory.cc:7:30: note: in instantiation of member function 'std::unordered_map<std::basic_string<char>, int>::unordered_map' requested here
7 | unordered_map<string, int> m;
| ^
In file included from hash_memory.cc:1:
In file included from /usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:595:
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:660:17: error: static assertion failed due to requirement 'integral_constant<bool, false>::value': the specified hash does not meet the Hash requirements
660 | static_assert(__check_hash_requirements<_Key, _Hash>::value,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/__hash_table:674:5: note: in instantiation of template class 'std::__enforce_unordered_container_requirements<std::basic_string<char>, std::hash<std::basic_string<char>>, std::equal_to<std::basic_string<char>>>' requested here
674 | typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type
| ^
/usr/local/Cellar/llvm/21.1.2/bin/../include/c++/v1/unordered_map:1099:26: note: while substituting explicitly-specified template arguments into function template '__diagnose_unordered_container_requirements'
1099 | static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
| ^
hash_memory.cc:7:30: note: in instantiation of member function 'std::unordered_map<std::basic_string<char>, int>::~unordered_map' requested here
7 | unordered_map<string, int> m;
| ^
6 errors generated.
egorpugin
Metadata
Metadata
Assignees
Labels
invalidResolved as invalid, i.e. not a bugResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.