C++11 and unordered_map

C++11 and unordered_map

Hello,

Just like in this thread, http://software.intel.com/en-us/forums/topic/394395, icpc is having difficulties compiling a simple C++11 compliant program with the GCC 4.8.1 headers.

icpc -std=c++11 emplace.cpp

include/c++/4.8.1/bits/hashtable.h(395): error: "_Hashtable" is not a nonstatic data member or base class of class
"std::_Hashtable<std::string, std::pair<const std::string, std::string>, std::allocator<std::pair<const std::string, std::string>>, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__umap_traits<true>>"
: _Hashtable(__n, __hf, __detail::_Mod_range_hashing(),
^
detected during:
instantiation of "std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_Hashtable(std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::size_type, const _H1 &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::key_equal &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy,
_Traits>::allocator_type &) [with _Key=std::string, _Value=std::pair<const std::string, std::string>, _Alloc=std::allocator<std::pair<const std::string, std::string>>, _ExtractKey=std::__detail::_Select1st, _Equal=std::equal_to<std::string>, _H1=std::hash<std::string>, _H2=std::__detail::_Mod_range_hashing, _Hash=std::__detail::_Default_ranged_hash, _RehashPolicy=std::__detail::_Prime_rehash_policy, _Traits=std::__umap_traits<true>]" at line 143 of
"include/c++/4.8.1/bits/unordered_map.h"
instantiation of "std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_equal &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::allocator_type &) [with _Key=std::string, _Tp=std::string, _Hash=std::hash<std::string>, _Pred=std::equal_to<std::string>,
_Alloc=std::allocator<std::pair<const std::string, std::string>>]" at line 8 of "emplace.cpp"

include/c++/4.8.1/bits/hashtable.h(395): error: expected a ")"
: _Hashtable(__n, __hf, __detail::_Mod_range_hashing(),
^
detected during:
instantiation of "std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_Hashtable(std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::size_type, const _H1 &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::key_equal &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy,
_Traits>::allocator_type &) [with _Key=std::string, _Value=std::pair<const std::string, std::string>, _Alloc=std::allocator<std::pair<const std::string, std::string>>, _ExtractKey=std::__detail::_Select1st, _Equal=std::equal_to<std::string>, _H1=std::hash<std::string>, _H2=std::__detail::_Mod_range_hashing, _Hash=std::__detail::_Default_ranged_hash, _RehashPolicy=std::__detail::_Prime_rehash_policy, _Traits=std::__umap_traits<true>]" at line 143 of
"include/c++/4.8.1/bits/unordered_map.h"
instantiation of "std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_equal &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::allocator_type &) [with _Key=std::string, _Tp=std::string, _Hash=std::hash<std::string>, _Pred=std::equal_to<std::string>,
_Alloc=std::allocator<std::pair<const std::string, std::string>>]" at line 8 of "emplace.cpp"

include/c++/4.8.1/bits/hashtable.h(398): error: no default constructor exists for class "std::__detail::_Hashtable_base<std::string, std::pair<const std::string, std::string>, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__umap_traits<true>>"
{ }
^
detected during:
instantiation of "std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_Hashtable(std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::size_type, const _H1 &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::key_equal &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy,
_Traits>::allocator_type &) [with _Key=std::string, _Value=std::pair<const std::string, std::string>, _Alloc=std::allocator<std::pair<const std::string, std::string>>, _ExtractKey=std::__detail::_Select1st, _Equal=std::equal_to<std::string>, _H1=std::hash<std::string>, _H2=std::__detail::_Mod_range_hashing, _Hash=std::__detail::_Default_ranged_hash, _RehashPolicy=std::__detail::_Prime_rehash_policy, _Traits=std::__umap_traits<true>]" at line 143 of
"include/c++/4.8.1/bits/unordered_map.h"
instantiation of "std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_equal &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::allocator_type &) [with _Key=std::string, _Tp=std::string, _Hash=std::hash<std::string>, _Pred=std::equal_to<std::string>,
_Alloc=std::allocator<std::pair<const std::string, std::string>>]" at line 8 of "emplace.cpp"

include/c++/4.8.1/bits/hashtable.h(398): error: no default constructor exists for class "std::__detail::_Before_begin<std::allocator<std::__detail::_Hash_node<std::pair<const std::string, std::string>, true>>>"
{ }
^
detected during:
instantiation of "std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_Hashtable(std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::size_type, const _H1 &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::key_equal &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy,
_Traits>::allocator_type &) [with _Key=std::string, _Value=std::pair<const std::string, std::string>, _Alloc=std::allocator<std::pair<const std::string, std::string>>, _ExtractKey=std::__detail::_Select1st, _Equal=std::equal_to<std::string>, _H1=std::hash<std::string>, _H2=std::__detail::_Mod_range_hashing, _Hash=std::__detail::_Default_ranged_hash, _RehashPolicy=std::__detail::_Prime_rehash_policy, _Traits=std::__umap_traits<true>]" at line 143 of
"include/c++/4.8.1/bits/unordered_map.h"
instantiation of "std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_equal &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::allocator_type &) [with _Key=std::string, _Tp=std::string, _Hash=std::hash<std::string>, _Pred=std::equal_to<std::string>,
_Alloc=std::allocator<std::pair<const std::string, std::string>>]" at line 8 of "emplace.cpp"

compilation aborted for emplace.cpp (code 2)

You can find the header file there: http://gcc.gnu.org/gcc-4.8/

Needless to say that the file compiles with G++ or Clang.

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Why is it not possible to edit the first post of a thread .. Anyway, the .cpp wasn't uploaded so here it is again.

Attachments: 

AttachmentSize
Downloadtext/x-c++src emplace.cpp464 bytes

Thanks for the test case.

>>...Why is it not possible to edit the first post of a thread...

That was already asked some time ago ( at least 3-month-old issue ) and so far there is No answer.

While I cannot test your code, I do recall an old bug in ICC that may have resurfaced. It would be easy enough for you to investigate (or Intel to investigate). This was for some constructs of templated the compiler took issue with ">>" (adjacent close angle bracktes). The work around was to insert a space "> >". If insertting the space corrects the problem then this will give the ICC developers something to work on, and more importantly, it will get you up and running while you await a fix.

Jim Dempsey

www.quickthreadprogramming.com

Thanks for the suggestion. Unfortunately, this didn't fix the problem (same errors). I attached the (original) header just in case people can't get their hands on hashtable.h.

Also note that icpc -v returns "icpc version 13.1.3 (gcc version 4.7.0 compatibility)" while I'm using gcc version 4.8.1. I guess this discrepancy is somehow linked to the failed compilation.

Attachments: 

AttachmentSize
Downloadtext/x-chdr hashtable.h61.05 KB

Please take into account that every C++ compiler has different degree of tolerance to some C++ declarations. For example, MSC is not too strict C++ compiler, and MinGW is a very strict C++ compiler ( I could give an example if needed ), and Intel C++ compiler is too strict ( just use /W5 and /check options and you'll see hundreds if not thousands of warnings ).

In your case Intel C++ compiler did a good job and detected that in one of these base classes::

* Base class templates are:
* - __detail::_Hashtable_base
* - __detail::_Map_base
* - __detail::_Insert
* - __detail::_Rehash_base
* - __detail::_Equality

there is No a default constructor ( you could easily reproduce that issue with a test case that has just 2 classes ). This is how that failing piece of codes looks like:
...
// Use delegating constructors.
explicit
_Hashtable(size_type __n = 10,
const _H1& __hf = _H1(),
const key_equal& __eql = key_equal(),
const allocator_type& __a = allocator_type())
: _Hashtable(__n, __hf, __detail::_Mod_range_hashing(),
__detail::_Default_ranged_hash(), __eql,
__key_extract(), __a)
{ }
...

A workaround, or a fix, is to add a default constructor where it needs to be.

I can't say anything regarding all the rest compilation errors.

Thanks to your remark and some modifications to hashtable.h and hashtable_policy.h, I now only have two errors left.

hashtable.h(397): error: "_Hashtable" is not a nonstatic data member or base class of class "std::_Hashtable<std::string, std::pair<const std::string, std::string>, std::allocator<std::pair<const std::string, std::string>>, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__umap_traits<true>>"
: _Hashtable(__n, __hf, __detail::_Mod_range_hashing(),
^
detected during:
instantiation of "std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_Hashtable(std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::size_type, const _H1 &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::key_equal &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy,
_Traits>::allocator_type &) [with _Key=std::string, _Value=std::pair<const std::string, std::string>, _Alloc=std::allocator<std::pair<const std::string, std::string>>, _ExtractKey=std::__detail::_Select1st, _Equal=std::equal_to<std::string>, _H1=std::hash<std::string>, _H2=std::__detail::_Mod_range_hashing, _Hash=std::__detail::_Default_ranged_hash, _RehashPolicy=std::__detail::_Prime_rehash_policy, _Traits=std::__umap_traits<true>]" at line 143 of
"include/c++/4.8.1/bits/unordered_map.h"
instantiation of "std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_equal &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::allocator_type &) [with _Key=std::string, _Tp=std::string, _Hash=std::hash<std::string>, _Pred=std::equal_to<std::string>,
_Alloc=std::allocator<std::pair<const std::string, std::string>>]" at line 10 of "emplace.cpp"

hashtable.h(397): error: expected a ")"
: _Hashtable(__n, __hf, __detail::_Mod_range_hashing(),
^
detected during:
instantiation of "std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_Hashtable(std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::size_type, const _H1 &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::key_equal &, const std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy,
_Traits>::allocator_type &) [with _Key=std::string, _Value=std::pair<const std::string, std::string>, _Alloc=std::allocator<std::pair<const std::string, std::string>>, _ExtractKey=std::__detail::_Select1st, _Equal=std::equal_to<std::string>, _H1=std::hash<std::string>, _H2=std::__detail::_Mod_range_hashing, _Hash=std::__detail::_Default_ranged_hash, _RehashPolicy=std::__detail::_Prime_rehash_policy, _Traits=std::__umap_traits<true>]" at line 143 of
"include/c++/4.8.1/bits/unordered_map.h"
instantiation of "std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_equal &, const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::allocator_type &) [with _Key=std::string, _Tp=std::string, _Hash=std::hash<std::string>, _Pred=std::equal_to<std::string>,
_Alloc=std::allocator<std::pair<const std::string, std::string>>]" at line 10 of "emplace.cpp"

If someone has any clue on how to fix that, I'd be very grateful.

Attachments: 

I found a temporary patch by just using the headers from gcc 4.7.1. It seems to work fine but I find that quite ugly. If someone has a better solution, please let me know. I'm still curious as to why it compiles fine with g++ and clang++, which are to my knowledge not the most "tolerant" compilers. For example, the following test case idea provided by Sergey obviously doesn't compile with either of them.

Quote:

Sergey Kostrov wrote:

there is No a default constructor ( you could easily reproduce that issue with a test case that has just 2 classes ). This is how that failing piece of codes looks like:

Leave a Comment

Please sign in to add a comment. Not a member? Join today