Boost C++ Libraries: Ticket #9035: Coroutine test code should produce segmentation fault, but actually not. https://svn.boost.org/trac10/ticket/9035 <p> According to Boost Coroutine documentation, the following piece of code shall produce segmentation fault, since "c"'s stack gets unwound and "x" should remain to be a nullptr, however "x" becomes non-null after the scoped coroutine code. </p> <p> I am not sure (since I am very new to Boost Coroutine lib) whether it is because of my mistake. </p> <p> My Boost 1.54 was compiled using Clang 3.3. I tested the code both using Clang 3.4 trunk and GCC 4.6.4. </p> <p> Thanks. </p> <p> =================================== </p> <p> #include &lt;boost/coroutine/all.hpp&gt; </p> <p> struct X { </p> <blockquote> <p> void g() {} </p> </blockquote> <p> }; </p> <p> typedef boost::coroutines::coroutine&lt;X*()&gt; coro_t; </p> <p> void fn(coro_t::caller_type&amp; ca) { </p> <blockquote> <p> X local; ca(&amp;local); </p> </blockquote> <p> } </p> <p> int main() { </p> <blockquote> <p> X* x = 0; { </p> <blockquote> <p> coro_t c(fn); x = c.get(); </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> x-&gt;g(); return 0; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9035 Trac 1.4.3 olli Thu, 22 Aug 2013 15:42:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9035#comment:1 https://svn.boost.org/trac10/ticket/9035#comment:1 <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> <p> add </p> <blockquote> <p> X() { </p> <blockquote> <p> std::cout &lt;&lt; "X()" &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <blockquote> <blockquote> <p> ~X() { </p> <blockquote> <p> std::cout &lt;&lt; "~X()" &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> void g() { </p> <blockquote> <p> std::cout &lt;&lt; "X::g()" &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> </blockquote> <p> and the output will be: </p> <p> X() ~X() X::g() </p> <p> the stack gets unwound but the objects (bit structure) is still available. </p> <p> change X to: </p> <p> struct X { </p> <blockquote> <p> int x; X() : x( 1) { </p> <blockquote> <p> std::cout &lt;&lt; "X(): " &lt;&lt; x &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> ~X() { </p> <blockquote> <p> x = 7; std::cout &lt;&lt; "~X(): " &lt;&lt; x &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> void g() { </p> <blockquote> <p> std::cout &lt;&lt; "X::g(): " &lt;&lt; x &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <p> }; </p> <p> and you will get your segmentation fault (gcc + clang) </p> Ticket