Boost C++ Libraries: Ticket #6919: g++ -std=c++11 breaks class inheritance with boost::shared_ptr https://svn.boost.org/trac10/ticket/6919 <p> 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) </p> <p> Compiler: GNU 4.7.0 Platforms: Centos 6.2, Mac OS X Lion Boost: 1.49.0 Python: 2.7.3 </p> <p> <em> Crash when running test3 produced by: </em>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 <em> </em> No crash when running test3 produced by: <em>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 </em> #include &lt;boost/python.hpp&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/make_shared.hpp&gt; #include &lt;iostream&gt; </p> <p> using namespace std; </p> <p> namespace bp = boost::python; </p> <p> struct Foo{ </p> <blockquote> <p> virtual void doSomething() { </p> <blockquote> <p> cout &lt;&lt; "Foo" &lt;&lt; endl; </p> </blockquote> <p> } </p> </blockquote> <p> }; </p> <p> struct Goo : Foo { </p> <blockquote> <p> virtual void doSomething() { </p> <blockquote> <p> cout &lt;&lt; "Goo" &lt;&lt; endl; </p> </blockquote> <p> } </p> </blockquote> <p> }; </p> <p> BOOST_PYTHON_MODULE(hello) { </p> <blockquote> <p> bp::class_&lt;Foo, boost::shared_ptr&lt;Foo&gt; &gt;("Foo") </p> <blockquote> <p> .def("doSomething", &amp;Foo::doSomething); </p> </blockquote> <p> bp::class_&lt;Goo, bp::bases&lt;Foo&gt;, boost::shared_ptr&lt;Goo&gt; &gt;("Goo"); </p> </blockquote> <p> }; <em> NOTE: Output works allright when there is no shared_ptr in bp::class_ above </em></p> <p> int main(int argc, char <strong>argv) { </strong></p> <blockquote> <p> Py_Initialize(); bp::object main = bp::import("<span class="underline">main</span>"); bp::object main_namespace = main.attr("<span class="underline">dict</span>"); inithello(); main_namespace<a class="missing wiki">hello</a> = bp::import("hello"); bp::exec("a = hello.Goo(); a.doSomething()", main_namespace); <em>Py_Main(argc, argv); Py_Finalize(); return 0; </em></p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6919 Trac 1.4.3 anonymous Fri, 18 May 2012 23:00:04 GMT <link>https://svn.boost.org/trac10/ticket/6919#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6919#comment:1</guid> <description> <p> After recompiling boost::python library using gcc 4.7 (using flags -std=c++11 -fno-strict-aliasing), the crash is not present anymore. This bug can be closed. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ralf W. Grosse-Kunstleve</dc:creator> <pubDate>Mon, 21 May 2012 03:21:42 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6919#comment:2 https://svn.boost.org/trac10/ticket/6919#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> Ticket Rob Stewart Wed, 18 Jul 2012 16:22:44 GMT <link>https://svn.boost.org/trac10/ticket/6919#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6919#comment:3</guid> <description> <p> According to <a class="ext-link" href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53455#c11"><span class="icon">​</span>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53455#c11</a>, this issue should not have been closed. -fno-strict-aliasing enables non-conforming behavior. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ralf W. Grosse-Kunstleve</dc:creator> <pubDate>Wed, 18 Jul 2012 19:20:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6919#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6919#comment:4</guid> <description> <p> Any code including Python.h needs to be compiled with -fno-strict-aliasing (because of the way <a class="missing wiki">PyObject</a> is implemented IIUC). </p> </description> <category>Ticket</category> </item> </channel> </rss>