Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static initialization order fiasco in utils.h #54

Open
PeterZhizhin opened this issue Jul 7, 2020 · 0 comments
Open

Static initialization order fiasco in utils.h #54

PeterZhizhin opened this issue Jul 7, 2020 · 0 comments

Comments

@PeterZhizhin
Copy link

There are two global variables in utils.h that cause a static initialization order fiasco: all_sinks and standard_sink.
The Sink class uses all_sinks in a constructor:

explicit Sink(SinkOptions o) : opts(o) { all_sinks.append(this); }

There is a global variable called standard_sink created as standard_sink(SinkOptions(STDERR_FILENO)).

As per C++ standard, the order of static variables initialization is undefined. Which means that standard_sink may be created before all_sinks is initialized. See https://isocpp.org/wiki/faq/ctors#static-init-order for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant