dimanche 25 août 2019

std::unordered_set of enum, calling find gives segmentation fault

#include <iostream>
#include <unordered_set>
#include <memory>

enum Config
{
    NO_NEW_LINE,
    TO_FILE,
    NO_CONSOLE
};

int main()
{
    std::shared_ptr<std::unordered_set<Config>> configurations;
    configurations->emplace(Config::NO_NEW_LINE);
    if (configurations->find(Config::NO_NEW_LINE) == configurations->end())
        std::cout << "nothing found " << std::endl;

    return 0;
}

I don't have any idea why this code gives segmentation fault.

Here's gdb (things were in namespace SLog)

0x00005555555b2a1a in std::_Hashtable<SLog::Config, SLog::Config, std::allocator<SLog::Config>, std::__detail::_Identity, std::equal_to<SLog::Config>, std::hash<SLog::Config>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, true, true> >::_M_bucket_index (this=0x0, __k=@0x7fffffffdbb4: SLog::NO_NEW_LINE, __c=0) at /usr/include/c++/7/bits/hashtable.h:631
631       { return __hash_code_base::_M_bucket_index(__k, __c, _M_bucket_count); }

Aucun commentaire:

Enregistrer un commentaire