https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115420

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
   Last reconfirmed|                            |2024-06-11
             Status|CLOSED                      |NEW
     Ever confirmed|0                           |1
         Resolution|INVALID                     |---

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If we add this to _Hashtable:

      template<typename>
        struct _Check_hash_requirements : true_type
        {
          static_assert(is_copy_constructible<_Hash>::value,
                        "custom hash function must be copy constructible");
          static_assert(is_destructible<_Hash>::value,
                        "custom hash function must be destructible");
        };

      template<typename _Tp>
        struct _Check_hash_requirements<hash<_Tp>> : true_type
        {
          static_assert(is_default_constructible<hash<_Tp>>::value,
                        "the std::hash<key_type> specialization is disabled");
        };
      static_assert(_Check_hash_requirements<_Hash>::value, "");


Then the first error is much clearer where the problem lies:

In file included from
/home/jwakely/gcc/15/include/c++/15.0.0/bits/unordered_map.h:33,
                 from /home/jwakely/gcc/15/include/c++/15.0.0/unordered_map:41,
                 from un.cc:1:
/home/jwakely/gcc/15/include/c++/15.0.0/bits/hashtable.h: In instantiation of
'struct std::_Hashtable<std::__cxx11::basic_string<char>, std::pair<const
std::__cxx11::basic_string<char>, long unsigned int>,
std::allocator<std::pair<const std::__cxx11::basic_string<char>, long unsigned
int> >, std::__detail::_Select1st,
std::equal_to<std::__cxx11::basic_string<char> >,
std::hash<std::__cxx11::basic_string<char> >,
std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash,
std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true,
false, true>
>::_Check_hash_requirements<std::hash<std::__cxx11::basic_string<char> > >':
/home/jwakely/gcc/15/include/c++/15.0.0/bits/hashtable.h:221:54:   required
from 'class std::_Hashtable<std::__cxx11::basic_string<char>, std::pair<const
std::__cxx11::basic_string<char>, long unsigned int>,
std::allocator<std::pair<const std::__cxx11::basic_string<char>, long unsigned
int> >, std::__detail::_Select1st,
std::equal_to<std::__cxx11::basic_string<char> >,
std::hash<std::__cxx11::basic_string<char> >,
std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash,
std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true,
false, true> >'
  221 |       static_assert(_Check_hash_requirements<_Hash>::value, "");
      |                                                      ^~~~~
/home/jwakely/gcc/15/include/c++/15.0.0/bits/unordered_map.h:112:18:   required
from 'class std::unordered_map<std::__cxx11::basic_string<char>, long unsigned
int>'
  112 |       _Hashtable _M_h;
      |                  ^~~~
un.cc:5:45:   required from here
    5 |   std::unordered_map<std::string, uint64_t> bar;
      |                                             ^~~
/home/jwakely/gcc/15/include/c++/15.0.0/bits/hashtable.h:218:62: error: static
assertion failed: the std::hash<key_type> specialization is disabled
  218 |           static_assert(is_default_constructible<hash<_Tp>>::value,
      |                                                              ^~~~~

So let's reopen this as a diagnostic RFE for the library.

Reply via email to