Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInitNew.cpp

    r8060b2b r39d8950  
    454454
    455455                auto expr = new ast::ImplicitCopyCtorExpr( appExpr->location, mutExpr );
    456                 // Move the type substitution to the new top-level. The substitution
    457                 // is needed to obtain the type of temporary variables so that copy
    458                 // constructor calls can be resolved.
     456                // Move the type substitution to the new top-level, if it is attached to the appExpr.
     457                // Ensure it is not deleted with the ImplicitCopyCtorExpr by removing it before deletion.
     458                // The substitution is needed to obtain the type of temporary variables so that copy constructor
     459                // calls can be resolved.
    459460                assert( typeSubs );
     461                // assert (mutExpr->env);
    460462                expr->env = tmp;
     463                // mutExpr->env = nullptr;
     464                //std::swap( expr->env, appExpr->env );
    461465                return expr;
    462466        }
    463467
    464468        void ResolveCopyCtors::previsit(const ast::Expr * expr) {
    465                 if ( nullptr == expr->env ) {
    466                         return;
    467                 }
    468                 GuardValue( env ) = expr->env->clone();
    469                 GuardValue( envModified ) = false;
     469                if (expr->env) {
     470                        GuardValue(env);
     471                        GuardValue(envModified);
     472                        env = expr->env->clone();
     473                        envModified = false;
     474                }
    470475        }
    471476
    472477        const ast::Expr * ResolveCopyCtors::postvisit(const ast::Expr * expr) {
    473                 // No local environment, skip.
    474                 if ( nullptr == expr->env ) {
    475                         return expr;
    476                 // Environment was modified, mutate and replace.
    477                 } else if ( envModified ) {
    478                         auto mutExpr = mutate(expr);
    479                         mutExpr->env = env;
    480                         return mutExpr;
    481                 // Environment was not mutated, delete the shallow copy before guard.
    482                 } else {
    483                         delete env;
     478                if (expr->env) {
     479                        if (envModified) {
     480                                auto mutExpr = mutate(expr);
     481                                mutExpr->env = env;
     482                                return mutExpr;
     483                        }
     484                        else {
     485                                // env was not mutated, skip and delete the shallow copy
     486                                delete env;
     487                                return expr;
     488                        }
     489                }
     490                else {
    484491                        return expr;
    485492                }
     
    490497        const ast::Expr * ResolveCopyCtors::makeCtorDtor( const std::string & fname, const ast::ObjectDecl * var, const ast::Expr * cpArg ) {
    491498                assert( var );
    492                 assert( var->isManaged() );
    493                 assert( !cpArg || cpArg->isManaged() );
     499                assert (var->isManaged());
     500                assert (!cpArg || cpArg->isManaged());
    494501                // arrays are not copy constructed, so this should always be an ExprStmt
    495502                ast::ptr< ast::Stmt > stmt = genCtorDtor(var->location, fname, var, cpArg );
     
    497504                auto exprStmt = stmt.strict_as<ast::ImplicitCtorDtorStmt>()->callStmt.strict_as<ast::ExprStmt>();
    498505                ast::ptr<ast::Expr> untyped = exprStmt->expr; // take ownership of expr
     506                // exprStmt->expr = nullptr;
    499507
    500508                // resolve copy constructor
     
    508516                        env->add( *resolved->env );
    509517                        envModified = true;
     518                        // delete resolved->env;
    510519                        auto mut = mutate(resolved.get());
    511520                        assertf(mut == resolved.get(), "newly resolved expression must be unique");
    512521                        mut->env = nullptr;
    513522                } // if
     523                // delete stmt;
    514524                if ( auto assign = resolved.as<ast::TupleAssignExpr>() ) {
    515525                        // fix newly generated StmtExpr
Note: See TracChangeset for help on using the changeset viewer.