{"action":"opened","issue":{"url":"https://api.github.com/repos/swig/swig/issues/731","repository_url":"https://api.github.com/repos/swig/swig","labels_url":"https://api.github.com/repos/swig/swig/issues/731/labels{/name}","comments_url":"https://api.github.com/repos/swig/swig/issues/731/comments","events_url":"https://api.github.com/repos/swig/swig/issues/731/events","html_url":"https://github.com/swig/swig/issues/731","id":162109024,"number":731,"title":"shared_ptr Derived -> Base conversion triggers memory ownership assert","user":{"login":"q-p","id":9739000,"avatar_url":"https://avatars.githubusercontent.com/u/9739000?v=3","gravatar_id":"","url":"https://api.github.com/users/q-p","html_url":"https://github.com/q-p","followers_url":"https://api.github.com/users/q-p/followers","following_url":"https://api.github.com/users/q-p/following{/other_user}","gists_url":"https://api.github.com/users/q-p/gists{/gist_id}","starred_url":"https://api.github.com/users/q-p/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/q-p/subscriptions","organizations_url":"https://api.github.com/users/q-p/orgs","repos_url":"https://api.github.com/users/q-p/repos","events_url":"https://api.github.com/users/q-p/events{/privacy}","received_events_url":"https://api.github.com/users/q-p/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-06-24T09:25:34Z","updated_at":"2016-06-24T09:25:34Z","closed_at":null,"body":"In the attached repo, I attempt to create a `vector<shared_ptr<Base> >` and I pass in a `shared_ptr<Derived>`. This leads to an assertion failure in `Assertion failed: (own), function SWIG_Python_ConvertPtrAndOwn, file Node_wrap.cxx, line 2385.`\r\n\r\nIs there any way to make this work correctly?\r\n\r\n`Node.hpp`\r\n```c++\r\n#ifndef NODE_HPP_3712EF25\r\n#define NODE_HPP_3712EF25\r\n\r\n#include <memory>\r\n#include <iostream>\r\n#include <vector>\r\n\r\nstruct Base\r\n{\r\n  virtual void Print() const { std::cout << \"Base\" << std::endl; }\r\n  static std::shared_ptr<Base> Make() { return std::make_shared<Base>(); }\r\n};\r\n\r\nstruct Derived : Base\r\n{\r\n  void Print() const override { std::cout << \"Derived\" << std::endl; }\r\n  static std::shared_ptr<Derived> Make() { return std::make_shared<Derived>(); }\r\n};\r\n\r\n#endif /* end of include guard: NODE_HPP_3712EF25 */\r\n```\r\n\r\n`Node.i`\r\n```swig\r\n%module Node\r\n\r\n// includes to compile the wrapper code\r\n%{\r\n#include \"Node.hpp\"\r\n%}\r\n\r\n// notify shared_ptrs\r\n%include <std_shared_ptr.i>\r\n%shared_ptr(Base)\r\n%shared_ptr(Derived)\r\n\r\n// load typemaps\r\n%include <std_vector.i>\r\n\r\n// and create wrappers\r\n%include \"Node.hpp\"\r\n\r\n%template(BaseVector) std::vector<std::shared_ptr<Base> >;\r\n```\r\n\r\n`test.py`\r\n```python\r\n#!/usr/bin/env python\r\n\r\nfrom Node import *\r\n\r\nl = [Base.Make(), Derived.Make()]\r\nvec = BaseVector(l)\r\n```\r\n\r\n`Makefile`\r\n```Makefile\r\n# it is important that NDEBUG is *not* defined, as otherwise the assert is disabled\r\n_%.so : %_wrap.cxx %.py\r\n\tclang++ -std=c++11 -UNDEBUG -g -fno-common -fno-strict-aliasing -fwrapv -dynamic -I/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/include/python2.7 -L/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -lpython2.7 -ldl -shared $< -o $@\r\n\r\n%_wrap.cxx %.py : %.i\r\n\tswig -c++ -python -fvirtual -shadow -modern $<\r\n\r\ntest : Node.py _Node.so test.py\r\n\tpython test.py\r\n\r\nclean :\r\n\trm -rf *.pyc Node_wrap.cxx Node.py _*.so*\r\n```\r\n\r\n[repo.zip](https://github.com/swig/swig/files/331526/repo.zip)\r\n\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"q-p"}}