Opened 9 years ago

Closed 9 years ago

#9035 closed Bugs (invalid)

Coroutine test code should produce segmentation fault, but actually not.

Reported by: anonymous Owned by: olli
Milestone: To Be Determined Component: coroutine
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

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.

I am not sure (since I am very new to Boost Coroutine lib) whether it is because of my mistake.

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.

Thanks.

===================================

#include <boost/coroutine/all.hpp>

struct X {

void g() {}

};

typedef boost::coroutines::coroutine<X*()> coro_t;

void fn(coro_t::caller_type& ca) {

X local; ca(&local);

}

int main() {

X* x = 0; {

coro_t c(fn); x = c.get();

}

x->g(); return 0;

}

Change History (1)

comment:1 by olli, 9 years ago

Resolution: invalid
Status: newclosed

add

X() {

std::cout << "X()" << std::endl;

}

~X() {

std::cout << "~X()" << std::endl;

}

void g() {

std::cout << "X::g()" << std::endl;

}

and the output will be:

X() ~X() X::g()

the stack gets unwound but the objects (bit structure) is still available.

change X to:

struct X {

int x; X() : x( 1) {

std::cout << "X(): " << x << std::endl;

}

~X() {

x = 7; std::cout << "~X(): " << x << std::endl;

}

void g() {

std::cout << "X::g(): " << x << std::endl;

}

};

and you will get your segmentation fault (gcc + clang)

Last edited 9 years ago by olli (previous) (diff)
Note: See TracTickets for help on using tickets.