Skip to content

cpp11::preserved relies on ordered global construction #224

Closed
@bkietz

Description

@bkietz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions