[Boost-bugs] [Boost C++ Libraries] #6919: g++ -std=c++11 breaks class inheritance with boost::shared_ptr

Subject: [Boost-bugs] [Boost C++ Libraries] #6919: g++ -std=c++11 breaks class inheritance with boost::shared_ptr
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-05-18 19:09:53


#6919: g++ -std=c++11 breaks class inheritance with boost::shared_ptr
--------------------------------------------------+-------------------------
 Reporter: altan@… | Owner: rwgk
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: Python
  Version: Boost 1.49.0 | Severity: Problem
 Keywords: boost python class inheritance c++11 |
--------------------------------------------------+-------------------------
 This simple program was developed to test sharing a C++ class with
 inheritance to Python. Output crashes inside boost::python when it is
 compiled by -std=c++11 flag in g++ 4.7.0 (NOTE: It works ok with g++ 4.4.6
 -std=c++0x)

 Compiler: GNU 4.7.0
 Platforms: Centos 6.2, Mac OS X Lion
 Boost: 1.49.0
 Python: 2.7.3

 // Crash when running test3 produced by:
 //g++ test3.cc -I../../ext/boost/Linux/include
 -I../../ext/python/Linux/include
 ../../ext/boost/Linux/lib/libboost_python.a
 ../../ext/python/Linux/lib/libpython.so -o test3 -std=c++11
 //
 // No crash when running test3 produced by:
 //g++ test3.cc -I../../ext/boost/Linux/include
 -I../../ext/python/Linux/include
 ../../ext/boost/Linux/lib/libboost_python.a
 ../../ext/python/Linux/lib/libpython.so -o test3
 //
 #include <boost/python.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/make_shared.hpp>
 #include <iostream>

 using namespace std;

 namespace bp = boost::python;

 struct Foo{
   virtual void doSomething() {
     cout << "Foo" << endl;
   }
 };

 struct Goo : Foo {
   virtual void doSomething() {
     cout << "Goo" << endl;
   }
 };


 BOOST_PYTHON_MODULE(hello) {
   bp::class_<Foo, boost::shared_ptr<Foo> >("Foo")
     .def("doSomething", &Foo::doSomething);
   bp::class_<Goo, bp::bases<Foo>, boost::shared_ptr<Goo> >("Goo");
 };
 // NOTE: Output works allright when there is no shared_ptr in bp::class_
 above

 int main(int argc, char **argv)
 {
     Py_Initialize();
     bp::object main = bp::import("__main__");
     bp::object main_namespace = main.attr("__dict__");
     inithello();
     main_namespace["hello"] = bp::import("hello");
     bp::exec("a = hello.Goo(); a.doSomething()", main_namespace);
     //Py_Main(argc, argv);
     Py_Finalize();
     return 0;
 }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6919>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC