[llvm-bugs] [Bug 32978] New: Cannot create shared_ptr of types with noexcept(false) destructor
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue May 9 08:47:13 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=32978
Bug ID: 32978
Summary: Cannot create shared_ptr of types with noexcept(false)
destructor
Product: libc++
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: marvin_schmidt at gmx.net
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
Created attachment 18422
--> https://bugs.llvm.org/attachment.cgi?id=18422&action=edit
patch to fix `make_shared<T>()` for types with noexcept(false) dtors
Hey folks,
I'm not sure if this is a bug in libc++ or not. But it's something, where
libstdc++ and libc++ behave differently. With libc++ calling
std::make_shared<T>() where T has a destructor marked `noexcept(false)` fails
to compile.
Test case:
#include <memory>
struct Foo
{
Foo() = default;
~Foo() noexcept(false) { throw 42; }
};
int main()
{
auto ptr = std::make_shared<Foo>();
return 0;
}
fails to compile with the following error:
# clang++ -std=c++11 -stdlib=libc++ -Wall -pedantic -O0 -o test test.cc
In file included from test.cc:1:
/usr/x86_64-pc-linux-gnu/bin/../include/c++/v1/memory:3589:7: error: exception
specification of overriding function is more lax than base version
class __shared_ptr_emplace
^
/usr/x86_64-pc-linux-gnu/bin/../include/c++/v1/memory:4228:26: note: in
instantiation of template class 'std::__1::__shared_ptr_emplace<Foo,
std::__1::allocator<Foo> >' requested here
::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
^
/usr/x86_64-pc-linux-gnu/bin/../include/c++/v1/memory:4598:29: note: in
instantiation of function template specialization
'std::__1::shared_ptr<Foo>::make_shared<>' requested here
return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
^
test.cc:11:25: note: in instantiation of function template specialization
'std::__1::make_shared<Foo>' requested here
auto ptr = std::make_shared<Foo>();
^
/usr/x86_64-pc-linux-gnu/bin/../include/c++/v1/memory:3498:13: note: overridden
virtual function is here
virtual ~__shared_weak_count();
^
1 error generated.
The attached patch fixes that by marking the destructors of
__shared_ptr_emplace, __shared_{,weak_}count with _NOEXCEPT, but I'm not sure,
if this is the way to go. It also is not a complete fix, since the
std::locale::facet for example is also derived from __shared_count and would
need to be adjusted accordingly as well.
I appreciate any insights on this
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170509/3ec0cc08/attachment.html>
More information about the llvm-bugs
mailing list