Changeset 5de1e2c


Ignore:
Timestamp:
May 31, 2018, 3:51:00 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
518e97d
Parents:
4e7cc5ce
git-author:
Rob Schluntz <rschlunt@…> (05/31/18 15:48:09)
git-committer:
Rob Schluntz <rschlunt@…> (05/31/18 15:51:00)
Message:

Fix memory error from caused by vector::push_back [fixes #90]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r4e7cc5ce r5de1e2c  
    324324                aggInst->lookup( name, members );
    325325
    326                 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
    327                         if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) {
    328                                 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) );
    329                                 renameTypes( alternatives.back().expr );
    330                                 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression.
     326                for ( Declaration * decl : members ) {
     327                        if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) {
     328                                // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so
     329                                // can't construct in place and use vector::back
     330                                Alternative newAlt( new MemberExpr( dwt, expr->clone() ), env, newCost );
     331                                renameTypes( newAlt.expr );
     332                                addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression.
     333                                alternatives.push_back( std::move(newAlt) );
    331334                        } else {
    332335                                assert( false );
     
    13791382                        Cost cost = Cost::zero;
    13801383                        Expression * newExpr = data.combine( cost );
    1381                         alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) );
     1384
     1385                        // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so
     1386                        // can't construct in place and use vector::back
     1387                        Alternative newAlt( newExpr, env, Cost::zero, cost );
    13821388                        PRINT(
    13831389                                std::cerr << "decl is ";
     
    13881394                                std::cerr << std::endl;
    13891395                        )
    1390                         renameTypes( alternatives.back().expr );
    1391                         addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression.
     1396                        renameTypes( newAlt.expr );
     1397                        addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression.
     1398                        alternatives.push_back( std::move(newAlt) );
    13921399                } // for
    13931400        }
Note: See TracChangeset for help on using the changeset viewer.