diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-06-02 04:57:00 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-06-02 04:57:00 +0000 |
commit | 7cf29e3468f7de38399abc756727f826ec6c6475 (patch) | |
tree | 60906d7477062494755b6e831f1ca108ec37645f /libcxx/test | |
parent | 048a08af664ea929678cca4823cae79ba66e9d62 (diff) | |
download | bcm5719-llvm-7cf29e3468f7de38399abc756727f826ec6c6475.tar.gz bcm5719-llvm-7cf29e3468f7de38399abc756727f826ec6c6475.zip |
Fix leak in __enable_weak_this(). Thanks to Arthur O'Dwyer for finding it.
llvm-svn: 271487
Diffstat (limited to 'libcxx/test')
-rw-r--r-- | libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp index 66933040671..6661e831ab8 100644 --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -26,6 +26,7 @@ #include <cassert> #include "test_macros.h" +#include "count_new.hpp" struct T : public std::enable_shared_from_this<T> @@ -62,7 +63,7 @@ int main() // * Using 'weak_from_this().expired()' in C++17. // * Using 'shared_from_this()' in all dialects. { - + assert(globalMemCounter.checkOutstandingNewEq(0)); T* ptr = new T; std::shared_ptr<T> s(ptr); { @@ -87,6 +88,37 @@ int main() } } #endif + s.reset(); + assert(globalMemCounter.checkOutstandingNewEq(0)); + } + // Test LWG issue 2529 again. This time check that an expired pointer + // is replaced. + { + assert(globalMemCounter.checkOutstandingNewEq(0)); + T* ptr = new T; + std::weak_ptr<T> weak; + { + std::shared_ptr<T> s(ptr, &nullDeleter); + assert(ptr->shared_from_this() == s); + weak = s; + assert(!weak.expired()); + } + assert(weak.expired()); + weak.reset(); + +#ifndef TEST_HAS_NO_EXCEPTIONS + try { + ptr->shared_from_this(); + assert(false); + } catch (std::bad_weak_ptr const&) { + } catch (...) { assert(false); } +#endif + { + std::shared_ptr<T> s2(ptr, &nullDeleter); + assert(ptr->shared_from_this() == s2); + } + delete ptr; + assert(globalMemCounter.checkOutstandingNewEq(0)); } // Test weak_from_this_methods #if TEST_STD_VER > 14 |