Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualCodarki

Posted 16 November 2012 - 01:54 PM

I don't actually know what happens in the following scenarios. Does goto respect rules of the scoped objects?
{
	std::string tee("hee");
	goto forward;
}
forward:
// what happens with destruction of tee? Memory leak I guess.
backward:
// what happens with destruction of tee? Memory leak I guess.
int i = 0;
if (i == 0)
{
	i = 1;
	std::string tee("hee");
	goto backward;
}
if (rand()%2 == 0)
	goto forward2;

{
	std::string tee("hee");
forward2:
	// tee isn't constructed here with goto. Crash if referenced I guess.
	// tee must be destructed at scope exit if entered without goto.
}

Does goto break all RAII objects?

#2Codarki

Posted 16 November 2012 - 01:54 PM

I don't actually know what happens in the following scenarios. Does goto respect rules of the scoped objects?
{
    std::string tee("hee");
    goto forward;
}
forward:
// what happens with destruction of tee? Memory leak I guess.
backward:
// what happens with destruction of tee? Memory leak I guess.
int i = 0;
if (i == 0)
{
    i = 1;
    std::string tee("hee");
    goto backward;
}
if (rand()%2 = 0)
    goto forward2;

{
    std::string tee("hee");
forward2:
    // tee isn't constructed here with goto. Crash if referenced I guess.
    // tee must be destructed at scope exit if entered without goto.
}

Does goto break all RAII objects?

#1Codarki

Posted 16 November 2012 - 01:51 PM

I don't actually know what happens in the following scenarios. Does goto respect rules of the scoped objects?
{
    std::string tee("hee");
    goto forward;
}
forward:
// what happens with destruction of tee? Memory leak I guess.
backward:
// what happens with destruction of tee? Memory leak I guess.
int i = 0;
if (i == 0)
{
    i = 1;
    std::string tee("hee");
    goto backward;
}
if (rand()%2 = 0)
    goto forward2:
{
    std::string tee("hee");
forward2:
    // tee isn't constructed here with goto. Crash if referenced I guess.
    // tee must be destructed at scope exit if entered without goto.
}

Does goto break all RAII objects?

PARTNERS