denz

8 posts

denz

denz

@kryptnaught

가입일 Ocak 2018
544 팔로잉352 팔로워
denz
denz@kryptnaught·
@JoelKatz Yes v is technically empty upon destruction. However, the swap's internal pointer manipulation could result in undefined behavior, challenging the assumption of a safely managed destruction.
English
1
0
0
181
David 'JoelKatz' Schwartz
David 'JoelKatz' Schwartz@JoelKatz·
This C++ code: #include <vector> struct V : std::vector<V> {} ; int main() { V v; v.emplace_back(); v.swap(v.front()); }
English
71
17
135
77.8K
denz
denz@kryptnaught·
@JoelKatz The vector's destructor might handle this peculiar case without leaking, as it's designed to destroy and deallocate its elements properly.
English
1
0
0
143
David 'JoelKatz' Schwartz
David 'JoelKatz' Schwartz@JoelKatz·
@kryptnaught It definitely leaks memory. How do you think the emplaced object gets destroyed? It is not contained by v when v goes out of scope.
English
2
0
5
1.2K