Unsolved Segfault on std::map creation?
-
In the following code, I get a segfault at the creation of the first pair. The weird thing is, the exact same code works when compiled with the latest standalone MinGW64, and this isn't my code, so I have no idea what the problem is. I'm using the latest Qt5.
assembler.cpp (link goes to line in GitHub repo)
// opcodes/byte codes functions mapping table typedef uint16_t (*callback)(t_token, Parser*); std::map<std::string, callback> opcodes_map; Assembler::Assembler() { opcodes_map["JP"] = &jumpOrCall; }
Is this a bug/missing feature in Qt's built-in compiler, or?
-
@adalovegirls said in Segfault on std::map creation?:
Qt's built-in compiler
Qt has no compiler... so what's the relation to Qt here?
Use a debugger and see where it exactly crashes -
@Christian-Ehrlicher I'm not sure what you mean. Qt5 ships with a built-in MinGW compiler.
Here's the debug trace:
1 libstdc++-6!_ZSt9use_facetISt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEEERKT_RKSt6locale 0x6fcfe12a 2 std::_Rb_tree_iterator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>::operator-- stl_tree.h 302 0x4323cb 3 std::_Rb_tree<std::string, std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>, std::_Select1st<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::less<std::string>, std::allocator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>>::_M_get_insert_unique_pos stl_tree.h 2063 0x436dac 4 std::_Rb_tree<std::string, std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>, std::_Select1st<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::less<std::string>, std::allocator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>>::_M_get_insert_hint_unique_pos stl_tree.h 2160 0x436f04 5 std::_Rb_tree<std::string, std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>, std::_Select1st<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::less<std::string>, std::allocator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>>::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<std::string&&>, std::tuple<>>(std::_Rb_tree_const_iterator<std::pair<std::string const, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>>, std::piecewise_construct_t const&, std::tuple<std::string&&>&&, std::tuple<>&&) stl_tree.h 2418 0x436c23 6 std::map<std::string, unsigned short ( *)(std::pair<TOKEN_TYPE, std::string>, Parser *)>::operator[] stl_map.h 518 0x432eec 7 Assembler::Assembler assembler.cpp 32 0x402d41 8 __static_initialization_and_destruction_0 debugger.cpp 36 0x40ff79 9 _GLOBAL__sub_I_disassembly debugger.cpp 391 0x40ffbb 10 __do_global_ctors 0x41d1b2 11 __tmainCRTStartup 0x40139a 12 WinMainCRTStartup 0x4014cb
The line in
7
that the trace refers to is:opcodes_map["JP"] = &jumpOrCall;
After that I have no idea what's happening because STL headers are way too complicated for me to understand as a beginner...
-
@adalovegirls said in Segfault on std::map creation?:
Qt5 ships with a built-in MinGW compiler
Qt is a C++ framework and not a compiler. Yes, you can install MinGW when installing Qt, but this does not mean that it is "built-in" in Qt.
-
@adalovegirls said in Segfault on std::map creation?:
jumpOrCall
Since this seems to be a global static somehwere I would guess jumpOrCall is not yet initialized. Don't use global statics!
Qt5 ships with a built-in MinGW compiler.
No, there is no Qt-build-in compiler. There is only a compiler which is used to compile Qt programs, nothing more.
-
Why did you delete the topic?