kripken/emscripten — Issue #270: compile errors with std::enable_shared_from_this
Author: Futumsh
Created: 2012-02-23 08:03:26+00:00
State: open

The following code (b.cpp):

#include

struct Foo : public std::enable_shared_from_this {};
struct Baz : public Foo {};

std::shared_ptr const bar()
{
return std::shared_ptr(new Baz);
}

int main(int, char **)
{
bar();
return 0;
}

Compiled with:
em++ b.cpp

Generates the following errors:

In file included from b.cpp:2:
emscripten/system/include/libcxx/memory:4025:5: error: no matching conversion for functional-style cast from 'const shared_ptr' to 'std::__1::weak_ptr'
weak_ptr(__r).swap(*this);
^~~~~~~~~~~~
emscripten/system/include/libcxx/memory:3183:35: note: in instantiation of function template specialization 'std::__1::weak_ptr::operator=' requested here
__e->__weak_this_ = *this;
^
emscripten/system/include/libcxx/memory:3218:5: note: in instantiation of function template specialization 'std::__1::shared_ptr::__enable_weak_this' requested here
__enable_weak_this(__p);
^
b.cpp:14:9: note: in instantiation of function template specialization 'std::__1::shared_ptr::shared_ptr' requested here
return std::shared_ptr(new Baz);
^
emscripten/system/include/libcxx/memory:3915:5: note: candidate constructor not viable: no known conversion from 'const shared_ptr' to 'const std::__1::weak_ptr' for 1st
argument;
weak_ptr(weak_ptr const& __r) _NOEXCEPT;
^
emscripten/system/include/libcxx/memory:3912:25: note: candidate template ignored: substitution failure [with _Yp = const Foo]
template weak_ptr(shared_ptr<_Yp> const& __r,
^
emscripten/system/include/libcxx/memory:3916:25: note: candidate template ignored: failed template argument deduction
template weak_ptr(weak_ptr<_Yp> const& __r,
^
emscripten/system/include/libcxx/memory:3911:5: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
weak_ptr() _NOEXCEPT;
^
1 error generated.