Skip to content

Returning a std::vector from C++ fails with STL debug mode enabled #1688

@mlaveaux

Description

@mlaveaux

It seems that enabling various STL debug features that change the ABI of standard data types might break accessing these types from the Rust side. Perhaps this is to be expected, but it did caught me by surprise. I used gcc to reproduce the issue, using the latest cxx version 1.0.191.

Here is a simple example that introduces a obtain_vector function, which returns a vector from the C++ side to the Rust side (via a UniquePtr<CxxVector<usize>> construction). Furthermore, it prints the values contained the in the vector on both sides. When running this example with the build.define calls in build.rs commented out we see the results I expect:

contains: 1
Obtained [1]

However, when running it with the various _LIBCPP_DEBUG_XXX and _GLIBCXX_DEBUG defines enabled I instead see the following output.

contains: 1
Obtained []

This also does not cause any segfaults or errors reported by AddressSanitizer.

cxx_bug.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions