Commit 4f63d614 by Jonathan Wakely Committed by Jonathan Wakely

Add more tests for enable_shared_from_this ambiguities

	* testsuite/20_util/enable_shared_from_this/56383.cc: Add tests for
	additional ambiguous cases.

From-SVN: r241364
parent 775669c1
2016-10-20 Jonathan Wakely <jwakely@redhat.com>
* testsuite/20_util/enable_shared_from_this/56383.cc: Add tests for
additional ambiguous cases.
2016-10-19 Jonathan Wakely <jwakely@redhat.com> 2016-10-19 Jonathan Wakely <jwakely@redhat.com>
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&)): Call * include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&)): Call
......
...@@ -20,37 +20,66 @@ ...@@ -20,37 +20,66 @@
#include <memory> #include <memory>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
struct A : std::enable_shared_from_this<A> template<typename T>
bool not_enabled(T& t)
{ {
void* a() { return shared_from_this().get(); } #if __cpp_lib_enable_shared_from_this >= 201603
}; return t.weak_from_this().expired();
#else
try {
t.shared_from_this();
return false;
} catch (const std::bad_weak_ptr&) {
return true;
}
#endif
}
struct B : std::enable_shared_from_this<B> struct A : std::enable_shared_from_this<A> { };
{ struct B : std::enable_shared_from_this<B> { };
}; struct D : A, B { };
struct D : A, B void test01()
{ {
}; auto d = std::make_shared<D>();
VERIFY( not_enabled( static_cast<A&>(*d) ) );
VERIFY( not_enabled( static_cast<const A&>(*d) ) );
VERIFY( not_enabled( static_cast<B&>(*d) ) );
VERIFY( not_enabled( static_cast<const B&>(*d) ) );
}
void test01() struct E : std::__enable_shared_from_this<E> { };
struct F : std::__enable_shared_from_this<F> { };
struct G : E, F { };
void test02()
{ {
bool test = false; auto g = std::make_shared<G>();
VERIFY( not_enabled( static_cast<E&>(*g) ) );
VERIFY( not_enabled( static_cast<const E&>(*g) ) );
VERIFY( not_enabled( static_cast<F&>(*g) ) );
VERIFY( not_enabled( static_cast<const F&>(*g) ) );
}
auto d = std::make_shared<D>(); struct H : D, G { };
try
{ void test03()
d->a(); {
} auto h = std::make_shared<H>();
catch (const std::bad_weak_ptr&) VERIFY( not_enabled( static_cast<A&>(*h) ) );
{ VERIFY( not_enabled( static_cast<const A&>(*h) ) );
test = true; VERIFY( not_enabled( static_cast<B&>(*h) ) );
} VERIFY( not_enabled( static_cast<const B&>(*h) ) );
VERIFY(test); VERIFY( not_enabled( static_cast<E&>(*h) ) );
VERIFY( not_enabled( static_cast<const E&>(*h) ) );
VERIFY( not_enabled( static_cast<F&>(*h) ) );
VERIFY( not_enabled( static_cast<const F&>(*h) ) );
} }
int int
main() main()
{ {
test01(); test01();
test02();
test03();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment