https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95200
Bug ID: 95200 Summary: user-defined hash function is not copied correctly if unordered_map is declared using an incomplete type Product: gcc Version: 9.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: jevgenijsz1 at verifone dot com Target Milestone: --- Created attachment 48558 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48558&action=edit g++ -v output The failing code requires at least 3 source files, I did not find a cleaner way to reproduce the issue. I'm not 100% sure this is a bug in libstdc++ however I couldn't find a reason for why this should not work as expected. Code: ===== map_obj.h ===== #ifndef MAP_OBJ_H_ #define MAP_OBJ_H_ #include <unordered_map> enum class EnumType; typedef std::unordered_map<EnumType, bool> map; class MapObj { public: map getEnumMap() const; map enum_map_; }; #endif ===== ===== map_obj.cpp ===== #include "map_obj.h" map MapObj::getEnumMap() const { return enum_map_; } ===== ===== main.cpp ===== #include <functional> enum class EnumType : int { VALUE0, VALUE1, }; namespace std { template <> struct hash<EnumType> { size_t operator()(EnumType type) const { return std::hash<int>()(static_cast<int>(type)); } }; } #include "map_obj.h" int main() { auto event = MapObj(); event.enum_map_[EnumType::VALUE0] = true; event.enum_map_[EnumType::VALUE1] = false; event.getEnumMap().at(EnumType::VALUE0); event.getEnumMap().at(EnumType::VALUE1); return 0; } ===== using: gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC) libstdc++ 3.4.28 command line to build: g++ -save-temps -Wall -Wextra -o map_test main.cpp map_obj.cpp expected result: runnnig map_test returns 0 actual result: terminate called after throwing an instance of 'std::out_of_range' what(): _Map_base::at