Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r446dde5 r53f4b55  
    393393
    394394StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss )
    395 : Expr( loc ), stmts( ss ) { computeResult(); }
     395: Expr( loc ), stmts( ss ), returnDecls(), dtors() { computeResult(); }
    396396
    397397void StmtExpr::computeResult() {
    398398        assert( stmts );
    399399        const std::list<ptr<Stmt>> & body = stmts->kids;
    400         // If there is a tail expression, its result is entire result.
    401         if ( !body.empty() && ( resultExpr = body.back().as<ExprStmt>() ) ) {
    402                 result = resultExpr->expr->result;
    403         // Otherwise, fill in the result with void so there is a result type.
    404         } else {
    405                 result = new VoidType();
    406         }
     400        if ( ! returnDecls.empty() ) {
     401                // prioritize return decl for result type, since if a return decl exists, then the StmtExpr
     402                // is currently in an intermediate state where the body will always give a void result type
     403                result = returnDecls.front()->get_type();
     404        } else if ( ! body.empty() ) {
     405                if ( const ExprStmt * exprStmt = body.back().as< ExprStmt >() ) {
     406                        result = exprStmt->expr->result;
     407                }
     408        }
     409        // ensure a result type exists
     410        if ( ! result ) { result = new VoidType{}; }
    407411}
    408412
Note: See TracChangeset for help on using the changeset viewer.