[cfe-dev] clang error: static_assert failed "Cache the hash code or make functors involved in hash code and bucket index computation default constructible"

Nema, Ashutosh via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 30 22:19:01 PST 2016


Hi,

Consider below test case:

     1  #include <unordered_map>
     2
     3  using key=const int;
     4  struct Myhash {
     5          Myhash() = default;
     6          std::hash<int> hash_int_t;
     7          inline size_t operator()(const key& x) const throw() {
     8                  return hash_int_t(x);
     9          }
    10  };
    11  std::unordered_map<key,int, Myhash> mm;

It compile with gcc (version 4.8.4) whereas I'm unable to compile same with clang.

Clang fails with below errors:

$ clang++ fail.cpp -std=c++11 -O0 -c
In file included from fail.cpp:1:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/unordered_map:47:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/hashtable.h:268:7: error: static_assert failed "Cache the hash code or make functors involved in hash code and bucket index computation default constructible"
      static_assert(__if_hash_not_cached<
      ^             ~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/unordered_map.h:120:36: error: member 'iterator' found in multiple base classes of different types
      typedef typename _Hashtable::iterator             iterator;
                                   ^
In file included from fail.cpp:1:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/unordered_map:48:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/unordered_map.h:121:36: error: member 'const_iterator' found in multiple base classes of different types
      typedef typename _Hashtable::const_iterator       const_iterator;

In file included from fail.cpp:1:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/unordered_map:48:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/unordered_map.h:124:36: error: member 'size_type' found in multiple base classes of different types
      typedef typename _Hashtable::size_type            size_type;
                                   ^

In file included from fail.cpp:1:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/unordered_map:48:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/unordered_map.h:452:7: error: multiple overloads of 'erase' instantiate to the same signature 'iterator (iterator)' (aka 'int (int)')
      erase(iterator __it)
      ^

Is this a known issue, or something I missed here ?

Regards,
Ashutosh

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161201/adbfc17b/attachment.html>


More information about the cfe-dev mailing list