diff --git a/src/script_opt/CPP/Stmts.cc b/src/script_opt/CPP/Stmts.cc index af9ba0baed..a28b4bae92 100644 --- a/src/script_opt/CPP/Stmts.cc +++ b/src/script_opt/CPP/Stmts.cc @@ -406,14 +406,14 @@ void CPPCompile::GenWhenStmt(const WhenStmt* w) Emit("{ // begin a new scope for internal variables"); - Emit("static WhenInfo* CPP__wi = nullptr;"); + Emit("static std::shared_ptr CPP__wi = nullptr;"); Emit("static IDSet CPP__w_globals;"); NL(); Emit("if ( ! CPP__wi )"); StartBlock(); - Emit("CPP__wi = new WhenInfo(%s);", is_return); + Emit("CPP__wi = std::make_shared(%s);", is_return); for ( auto& wg : wi->WhenExprGlobals() ) Emit("CPP__w_globals.insert(find_global__CPP(\"%s\").get());", wg->Name()); EndBlock();