I'm curious how gflags avoids the problem of varying order of initialization of static-lifetime variables. The comments in the code indicate clearly that a lot of thought has gone into it, but the code itself contains a couple of things which look like bugs. Well, they look like bugs to me.
The static initialization order fiasco problem is well-known: after program startup but before main() is called, all the static-lifetime variables with non-constexpr initializer expressions are initialized in no particular order. If one of those expressions implicitly assumes that another global variable has already completed its initialization, then disaster results.
Gflags relies on construction and use of map and string objects at static-initialization time. Those are non-POD classes. Nothing in the language standard promises that they won't rely on dynamically-initialized static variables.
So, how do we know that a DEFINE_string won't be run before the initializer for a hidden static variable inside the map implementation? If an implementation has such a hidden static var, and the map constructor depends on it not being zero, then the world will collapse randomly on program startup.
Now, what saves the world here? Is map required by something to be fully operational before dynamic initialization begins? If so, by what? Or is there another cunning plan which prevents this being a problem? Or, is it just a problem?
--Adrian.
professional nit-picker