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

unordered_set move leads to crash in 1.80.0 #139

Closed
ergpudb opened this issue Aug 16, 2022 · 3 comments
Closed

unordered_set move leads to crash in 1.80.0 #139

ergpudb opened this issue Aug 16, 2022 · 3 comments

Comments

@ergpudb
Copy link

ergpudb commented Aug 16, 2022

This code segfaults in 1.80.0 but not 1.79.0 (nor using std::unordered_set):

    boost::unordered_set<std::string> a;
    boost::unordered_set<std::string> b = std::move(a);
    boost::unordered_set<std::string> c = std::move(a);
    c.clear(); // <-- segfault

Based on the standard, the first move should leave a in a "valid but unspecified state"; since a should still be valid, moving from it a second time presumably should not corrupt c (even if the contents of c are technically unspecified afterward).

Note: it appears that unordered_map also exhibits the same behavior.

@ergpudb
Copy link
Author

ergpudb commented Aug 16, 2022

Even simpler (no double move):

    boost::unordered_set<std::string> a;
    boost::unordered_set<std::string> b = std::move(a);
    a.clear(); // <-- segfault

@ergpudb ergpudb changed the title unordered_set double move leads to crash in 1.80.0 unordered_set move leads to crash in 1.80.0 Aug 16, 2022
@cmazakas
Copy link
Member

Thank you for the bug report!

I've replicated this issue locally and am aware of the cause.

I'm working on the fix.

@cmazakas
Copy link
Member

cmazakas commented Nov 1, 2022

@ergpudb this fix will be landing in 1.81. In the interim, I'm going to close the issue.

@cmazakas cmazakas closed this as completed Nov 1, 2022
rwgk pushed a commit to rwgk/pybind11 that referenced this issue Dec 29, 2023
boostorg/unordered#139

> Based on the standard, the first move should leave a in a "valid but unspecified state";
rwgk pushed a commit to rwgk/pybind11 that referenced this issue Dec 29, 2023
boostorg/unordered#139

> Based on the standard, the first move should leave a in a "valid but unspecified state";
rwgk referenced this issue in pybind/pybind11 Dec 29, 2023
Clazy's warning (non-pod-global-static) is not relevant for
test code.
rwgk pushed a commit to pybind/pybind11 that referenced this issue Dec 30, 2023
* stl.h: Use C++11 range-loops with const reference

This saves copy-ctor and dtor for non-trivial types by value
Found by clazy (range-loop-reference)

* test_smart_ptr.cpp cleanup

Introduce `pointer_set<T>`

boostorg/unordered#139

> Based on the standard, the first move should leave a in a "valid but unspecified state";

---------

Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]>
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

2 participants