https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98220

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #6)
> I bet it's related to the construction of the s_creator and its usage at
> moduleB.cpp:8
> It's likely Static Initialization Order Fiasco:
> https://en.cppreference.com/w/cpp/language/siof
> 
> @Jonathan: Can you please judge?

Agreed. Either all the REGISTER_MODULE objects need to be created in the same
translation unit, after the definition of s_creator, or you need to initialize
s_creator as needed e.g.

class ModuleFactory
{
...
private:
    static std::unordered_map<std::string, Module::creator_t>& s_creator()
    {
        static std::unordered_map<std::string, Module::creator_t> s_map;
        return s_map;
    };
};

Reply via email to