summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/utilities
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-06-26 23:56:32 +0000
committerEric Fiselier <eric@efcs.ca>2016-06-26 23:56:32 +0000
commit39005d30196c67e1b4e4e3cdbc9f43c8bcd24f91 (patch)
treee31653765946bb4500afd09ee2f204bd4c5fd357 /libcxx/test/std/utilities
parent819f3b95aed74e7be8837a1ef359593c07e0d733 (diff)
downloadbcm5719-llvm-39005d30196c67e1b4e4e3cdbc9f43c8bcd24f91.tar.gz
bcm5719-llvm-39005d30196c67e1b4e4e3cdbc9f43c8bcd24f91.zip
Fix PR27115 - enable_shared_from_this does not work as a virtual base class.
See https://llvm.org/bugs/show_bug.cgi?id=27115 The problem was that the conversion from 'const enable_shared_from_this<T>*' to 'const T*' didn't work if T inherited enable_shared_from_this as a virtual base class. The fix is to take the original pointer passed to shared_ptr's constructor in the __enable_weak_this method and perform an upcast to 'const T*' instead of performing a downcast from the enable_shared_from_this base. llvm-svn: 273835
Diffstat (limited to 'libcxx/test/std/utilities')
-rw-r--r--libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp16
1 files changed, 16 insertions, 0 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 6661e831ab8..baee66e123e 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
@@ -39,12 +39,28 @@ struct Z : Y {};
void nullDeleter(void*) {}
+struct Foo : virtual public std::enable_shared_from_this<Foo>
+{
+ virtual ~Foo() {}
+};
+
+struct Bar : public Foo {
+ Bar(int) {}
+};
+
+
int main()
{
{ // https://llvm.org/bugs/show_bug.cgi?id=18843
std::shared_ptr<T const> t1(new T);
std::shared_ptr<T const> t2(std::make_shared<T>());
}
+ { // https://llvm.org/bugs/show_bug.cgi?id=27115
+ std::shared_ptr<Bar> t1(new Bar(42));
+ assert(t1->shared_from_this() == t1);
+ std::shared_ptr<Bar> t2(std::make_shared<Bar>(42));
+ assert(t2->shared_from_this() == t2);
+ }
{
std::shared_ptr<Y> p(new Z);
std::shared_ptr<T> q = p->shared_from_this();
OpenPOWER on IntegriCloud