[llvm-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 llvm-dev llvm-dev at lists.llvm.org
Thu Dec 1 20:54:23 PST 2016


Thanks Brian for pointing out.

Yes my libstdc++ doesn't have mentioned fix, after applying it worked !.

Regards,
Ashutosh

From: Brian Cain [mailto:bcain at codeaurora.org]
Sent: Thursday, December 1, 2016 7:59 PM
To: Nema, Ashutosh <Ashutosh.Nema at amd.com>; cfe-dev at lists.llvm.org
Subject: RE: [llvm-dev] clang error: static_assert failed "Cache the hash code or make functors involved in hash code and bucket index computation default constructible"

Is it related to this libstdc++ bug?

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

Does your libstdc++'s hashtable_policy.h have this change?

https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/include/bits/hashtable_policy.h?r1=195935&r2=195934&pathrev=195935

FWIW this test case works on clang 3.6 and 3.9.0 with the libstdc++ at Godbolt https://godbolt.org/g/beq77a

-Brian

From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Nema, Ashutosh via llvm-dev
Sent: Thursday, December 1, 2016 12:19 AM
To: llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>>; cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
Subject: [llvm-dev] clang error: static_assert failed "Cache the hash code or make functors involved in hash code and bucket index computation default constructible"

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/llvm-dev/attachments/20161202/9e8cc5b4/attachment.html>


More information about the llvm-dev mailing list