<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 --- - std::make_shared will fail to compile for a const class with a default constructor" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24137&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=--_HltvPQTeu7dHLyRGOyWlr9IV4P07Nrj-SF7U0HCA&s=fl6Bm5dFL4QgL2jgfce7oq33VJegj-rYW8R0lu9qqIk&e=">24137</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>std::make_shared will fail to compile for a const class with a default constructor
</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>Linux
</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>krasin@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>The following code will fail to compile:
#include <memory>
class Lala {
public:
Lala() = default;
//Lala() {}
virtual ~Lala() = default;
};
int main(void) {
const auto ptr = std::make_shared<const Lala>();
}
The error message is unsettling:
/usr/local/include/c++/v1/memory:2119:40: error: constructor for
'std::__1::__libcpp_compressed_pair_imp<std::__1::allocator<const Lala>, const
Lala, 1>' must explicitly initialize the const member '__second_'
_LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param
__t1)
^
/usr/local/include/c++/v1/memory:2389:11: note: in instantiation of member
function 'std::__1::__libcpp_compressed_pair_imp<std::__1::allocator<const
Lala>, const Lala, 1>::__libcpp_compressed_pair_imp' requested here
: base(_VSTD::forward<_T1_param>(__t1)) {}
^
/usr/local/include/c++/v1/memory:3771:12: note: in instantiation of member
function 'std::__1::__compressed_pair<std::__1::allocator<const Lala>, const
Lala>::__compressed_pair' requested here
: __data_(_VSTD::move(__a)) {}
^
/usr/local/include/c++/v1/memory:4366:26: note: in instantiation of member
function 'std::__1::__shared_ptr_emplace<const Lala, std::__1::allocator<const
Lala> >::__shared_ptr_emplace' requested here
::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
^
/usr/local/include/c++/v1/memory:4730:29: note: in instantiation of function
template specialization 'std::__1::shared_ptr<const Lala>::make_shared<>'
requested here
return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
^
/home/krasin/make_shared.cc:11:25: note: in instantiation of function template
specialization 'std::__1::make_shared<const Lala>' requested here
const auto ptr = std::make_shared<const Lala>();
^
/usr/local/include/c++/v1/memory:2107:9: note: '__second_' declared here
_T2 __second_;
^
1 error generated.
I suspect this could be related to <a class="bz_bug_link
bz_status_RESOLVED bz_closed" title="RESOLVED WORKSFORME - Error in std::pair default constructor when elements are not default-constructible" href="show_bug.cgi?id=21917">https://llvm.org/bugs/show_bug.cgi?id=21917</a>,
but my feelings are that it's a different bug. Feel free to close this one, and
I will reopen 21917.</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>