When moving an unordered_set
out on GCC 4.9, and then reusing the moved-from object, I am getting a divide-by-zero when I add to it.
My understanding (from http://en.cppreference.com/w/cpp/utility/move) is that the moved-from object can be used provided none of its preconditions are violated. Calling clear()
on the moved-from set is fine (which makes sense in the context of preconditions), but it's not clear to me that I'm violating any precondition by adding a new element.
Example code:
#include <unordered_set>
using namespace std;
void foo(unordered_set<int> &&a) {
unordered_set<int> copy = std::move(a);
}
void test() {
unordered_set<int> a;
for (int i = 0; i < 12; ++i) a.insert(i);
foo(std::move(a));
a.clear();
a.insert(34); // divide by zero here
}
int main() {
test();
}
This code works fine on GCC4.7 - is this an issue in GCC4.9's unordered_set
implementation, or in my understanding of what it means to violate preconditions on moved-from objects?
This is PR 61143. It has been fixed for gcc-4.10 and the fix has been backported in time for 4.9.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With