<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - enable_shared_from_this doesn't work when setting a pointer to a base class without enable_shared_from_this"
href="https://llvm.org/bugs/show_bug.cgi?id=25380">25380</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>enable_shared_from_this doesn't work when setting a pointer to a base class without enable_shared_from_this
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>agbakken@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=15204" name="attach_15204" title="source file demonstrating the problem">attachment 15204</a> <a href="attachment.cgi?id=15204&action=edit" title="source file demonstrating the problem">[details]</a></span>
source file demonstrating the problem
The following example doesn't compile on clang --version:
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
To build:
clang++ main.cpp -o enable_shared_from_this_bug
In file included from main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4032:35:
error: no viable overloaded '='
__e->__weak_this_ = *this;
~~~~~~~~~~~~~~~~~ ^ ~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4070:5:
note: in instantiation of function template specialization
'std::__1::shared_ptr<Base>::__enable_weak_this<Sub>' requested here
__enable_weak_this(__p);
^
main.cpp:14:27: note: in instantiation of function template specialization
'std::__1::shared_ptr<Base>::shared_ptr<Sub>' requested here
std::shared_ptr<Base> base(new Sub);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4984:15:
note: candidate function not viable: no known conversion from
'std::__1::shared_ptr<Base>' to 'const std::__1::weak_ptr<Sub>' for 1st
argument
weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4991:9:
note: candidate template ignored: could not match 'weak_ptr' against
'shared_ptr'
operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:5009:13:
note: candidate template ignored: disabled by 'enable_if' [with _Yp = Base]
is_convertible<_Yp*, element_type*>::value,
^
1 error generated.
make: *** [all] Error 1
This compile on gcc 5.2.1 on Ubuntu 15.10.
This patch fixes the problem:
--- /tmp/memory 2015-11-02 11:13:37.000000000 -0800
+++
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory
2015-11-02 11:24:02.000000000 -0800
@@ -4029,7 +4029,7 @@
__enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
{
if (__e)
- __e->__weak_this_ = *this;
+ __e->__weak_this_ = shared_ptr<_Yp>(*this,
static_cast<_Yp*>(get()));
}
_LIBCPP_INLINE_VISIBILITY</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>