summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/utilities
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2017-05-10 19:35:49 +0000
committerEric Fiselier <eric@efcs.ca>2017-05-10 19:35:49 +0000
commitf09df7723636fb0cbd7cda44f79dae5abb917566 (patch)
treef89d95ac225f274af5778e54c2e3dfdc10751b54 /libcxx/test/std/utilities
parentd7dc225888b7f6925099cdb0fe4da77a62dd74d4 (diff)
downloadbcm5719-llvm-f09df7723636fb0cbd7cda44f79dae5abb917566.tar.gz
bcm5719-llvm-f09df7723636fb0cbd7cda44f79dae5abb917566.zip
[libc++] Fix PR32979 - types with a private std::enable_shared_from_this base break shared_ptr
Summary: This patch fixes bugs.llvm.org/PR32979. [util.smartptr.shared.const] says: > In the constructor definitions below, enables shared_from_this with p, for a pointer p of type Y*, means > that if Y has an unambiguous and accessible base class that is a specialization of enable_shared_from_- > this. This means that libc++ needs to respect the access specifier of the base class, and not attempt to construct and enabled_shared_from_this base if it is private. However access specifiers don't affect overload resolution so our current implementation will attempt to construct the private base. This patch uses SFINAE to correctly detect if the shared_ptr input has an accessible enable_shared_from_this base class. Reviewers: mclow.lists Reviewed By: mclow.lists Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33033 llvm-svn: 302709
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.cpp11
1 files changed, 11 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 5a0d9259c11..5124e025253 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
@@ -49,6 +49,11 @@ struct Bar : public Foo {
};
+struct PrivateBase : private std::enable_shared_from_this<PrivateBase> {
+ std::weak_ptr<PrivateBase> get_weak() { return weak_from_this(); }
+};
+
+
int main()
{
{ // https://bugs.llvm.org/show_bug.cgi?id=18843
@@ -74,6 +79,12 @@ int main()
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
+ {
+ typedef std::shared_ptr<PrivateBase> APtr;
+ typedef std::weak_ptr<PrivateBase> WeakAPtr;
+ APtr a1 = std::make_shared<PrivateBase>();
+ assert(a1.use_count() == 1);
+ }
// Test LWG issue 2529. Only reset '__weak_ptr_' when it's already expired.
// http://cplusplus.github.io/LWG/lwg-active.html#2529.
// Test two different ways:
OpenPOWER on IntegriCloud