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

cpp11::preserved relies on ordered global construction #224

Closed
bkietz opened this issue Aug 11, 2021 · 0 comments · Fixed by #223
Closed

cpp11::preserved relies on ordered global construction #224

bkietz opened this issue Aug 11, 2021 · 0 comments · Fixed by #223

Comments

@bkietz
Copy link
Collaborator

bkietz commented Aug 11, 2021

cpp11::preserved relies on the list_ data member having a well-defined value at the time preserved is accessed. Since the order of construction of globals is not guaranteed in c++, that can lead to undefined behavior if you're constructing (for example) a global cpp11::strings since that appends to preserved in the constructor.

namespace {

// the value of `cpp11::preserved.list_` is not guaranteed here!
cpp11::strings kColorStrings = cpp11::writable::strings({
  "red",
  "green",
  "blue",
});

} // namespace
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

Successfully merging a pull request may close this issue.

1 participant