Goto out of a block: do destructors get called?

后端 未结 4 747
陌清茗
陌清茗 2020-12-28 12:14

Consider the following code:

void foo()
{
    {
        CSomeClass bar;

        // Some code here...

        goto label;

        // and here...
    }

lab         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 12:30

    Yes, they will be called.

    Update: (it's okay to do this, gotos is not worse than throwing dummy exceptions or using bools/ifs to get out of things. A simple goto inside a function don't make it spaghetti code.)

提交回复
热议问题