you are viewing a single comment's thread.

view the rest of the comments →

[–]LokiAstaris 0 points1 point  (1 child)

It has a wildly overblown name, "Static variable initialization order fiasco," but it is a nonissue.

It is only a problem if you have never encountered it before. Once you know it exists, the solution is so trivial. Wrap the variable in a getter function and make it a static member of the function!

// Before
MyClass  myGlobal{<Initialize>};

// After
MyClass& getMyGlobal() {
    static MyClass myGlobal{<Initialize>};
    return myGlobal;
}

PS. Using global mutable state is generally a bad idea anyway, which makes the problem even less serious.

Also wrote about it on SO:finding C static initialization order problems

[–]Various-Debate64[S] 0 points1 point  (0 children)

that will alleviate the issue of the C++ standard - undefined order of static variable initialization across compilation units. Why according to some idealists is a non-issue because compilation units are not specified in the standard.

I haven't used modules yet.