vendredi 28 février 2020

unodered_map is compiling fine but segfaults on execution

I am having difficulty in understanding why the below program is giving core dump on execution.

   #include <iostream>
   #include <unordered_map>
   using namespace std;
   int main()
   {
       std::unordered_map<int,int> hMap;
       return 0;
   }

There is no compilation warnings or errors but it gives core dump when I execute it. Is this issue related to the platform or compiler? Or am I missing something here?

I am compiling the code using below g++ command

g++ -g -Wall -Werror -std=c++11 -o file file.cpp

Platform is

Linux 3.10.0-1062.4.1.el7.x86_64 #1 SMP Wed Sep 25 09:42:57 EDT 2019 x86_64 x86_64 x86_64 GNU/Linux

Compiler :

gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)

On debugging I am getting the following stacktrace:

#0  0x0000000000601e30 in memset@@GLIBC_2.2.5 ()
#1  0x0000000000400fd4 in std::_Hashtable<int, std::pair<int const, int>, std::allocator<std::pair<int const, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_allocate_buckets (
    this=0x7ffffffe8310, __n=11) at /usr/include/c++/4.8.2/bits/hashtable.h:780
#2  0x0000000000400db4 in std::_Hashtable<int, std::pair<int const, int>, std::allocator<std::pair<int const, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_Hashtable (this=0x7ffffffe8310, 
    __bucket_hint=10, __h1=..., __h2=..., __h=..., __eq=..., __exk=..., __a=...) at /usr/include/c++/4.8.2/bits/hashtable.h:831
#3  0x0000000000400bc5 in std::_Hashtable<int, std::pair<int const, int>, std::allocator<std::pair<int const, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::---Type <return> to continue, or q <return> to quit---
__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_Hashtable (this=0x7ffffffe8310, 
    __n=10, __hf=..., __eql=..., __a=...) at /usr/include/c++/4.8.2/bits/hashtable.h:397
#4  0x0000000000400aff in std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, int> > >::unordered_map (this=0x7ffffffe8310, __n=10, __hf=..., __eql=..., __a=...)
    at /usr/include/c++/4.8.2/bits/unordered_map.h:142

Aucun commentaire:

Enregistrer un commentaire