Index: src/AST/Attribute.hpp
===================================================================
--- src/AST/Attribute.hpp	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/AST/Attribute.hpp	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -9,7 +9,7 @@
 // Author           : Aaron B. Moss
 // Created On       : Fri May 10 10:30:00 2019
-// Last Modified By : Aaron B. Moss
+// Last Modified By : Peter A. Buhr
 // Created On       : Fri May 10 10:30:00 2019
-// Update Count     : 1
+// Update Count     : 2
 //
 
@@ -34,5 +34,5 @@
 
 	Attribute( const std::string & name = "", std::vector<ptr<Expr>> && params = {})
-	: name( name ), params( params ) {}
+		: name( name ), params( params ) {}
 	virtual ~Attribute() = default;
 
Index: src/GenPoly/Box.cpp
===================================================================
--- src/GenPoly/Box.cpp	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/GenPoly/Box.cpp	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -366,6 +366,7 @@
 
 	/// Passes extra layout arguments for sized polymorphic type parameters.
-	ast::vector<ast::Expr>::iterator passTypeVars(
+	void passTypeVars(
 		ast::ApplicationExpr * expr,
+		ast::vector<ast::Expr> & extraArgs,
 		ast::FunctionType const * funcType );
 	/// Wraps a function application with a new temporary for the
@@ -387,6 +388,6 @@
 	/// parameter list. arg should point into expr's argument list.
 	void boxParams(
-		ast::ApplicationExpr const * expr,
-		ast::vector<ast::Expr>::iterator arg,
+		ast::ApplicationExpr * expr,
+		ast::Type const * polyRetType,
 		ast::FunctionType const * function,
 		const TypeVarMap & typeVars );
@@ -395,5 +396,5 @@
 	void addInferredParams(
 		ast::ApplicationExpr * expr,
-		ast::vector<ast::Expr>::iterator arg,
+		ast::vector<ast::Expr> & extraArgs,
 		ast::FunctionType const * functionType,
 		const TypeVarMap & typeVars );
@@ -636,8 +637,4 @@
 	ast::Expr const * ret = expr;
 
-	// TODO: This entire section should probably be refactored to do less
-	// pushing to the front/middle of a vector.
-	ptrdiff_t initArgCount = mutExpr->args.size();
-
 	TypeVarMap exprTypeVars;
 	makeTypeVarMap( function, exprTypeVars );
@@ -662,13 +659,10 @@
 	}
 
-	assert( typeSubs );
-	ast::vector<ast::Expr>::iterator argIt =
-		passTypeVars( mutExpr, function );
-	addInferredParams( mutExpr, argIt, function, exprTypeVars );
-
-	argIt = mutExpr->args.begin();
-	std::advance( argIt, ( mutExpr->args.size() - initArgCount ) );
-
-	boxParams( mutExpr, argIt, function, exprTypeVars );
+	ast::vector<ast::Expr> prependArgs;
+	passTypeVars( mutExpr, prependArgs, function );
+	addInferredParams( mutExpr, prependArgs, function, exprTypeVars );
+
+	boxParams( mutExpr, dynRetType, function, exprTypeVars );
+	spliceBegin( mutExpr->args, prependArgs );
 	passAdapters( mutExpr, function, exprTypeVars );
 
@@ -766,9 +760,9 @@
 }
 
-ast::vector<ast::Expr>::iterator CallAdapter::passTypeVars(
+void CallAdapter::passTypeVars(
 		ast::ApplicationExpr * expr,
+		ast::vector<ast::Expr> & extraArgs,
 		ast::FunctionType const * function ) {
 	assert( typeSubs );
-	ast::vector<ast::Expr>::iterator arg = expr->args.begin();
 	// Pass size/align for type variables.
 	for ( ast::ptr<ast::TypeInstType> const & typeVar : function->forall ) {
@@ -780,12 +774,9 @@
 						   toString( typeSubs ).c_str(), typeVar->typeString().c_str() );
 		}
-		arg = expr->args.insert( arg,
+		extraArgs.emplace_back(
 			new ast::SizeofExpr( expr->location, ast::deepCopy( concrete ) ) );
-		arg++;
-		arg = expr->args.insert( arg,
+		extraArgs.emplace_back(
 			new ast::AlignofExpr( expr->location, ast::deepCopy( concrete ) ) );
-		arg++;
-	}
-	return arg;
+	}
 }
 
@@ -913,8 +904,12 @@
 
 void CallAdapter::boxParams(
-		ast::ApplicationExpr const * expr,
-		ast::vector<ast::Expr>::iterator arg,
+		ast::ApplicationExpr * expr,
+		ast::Type const * polyRetType,
 		ast::FunctionType const * function,
 		const TypeVarMap & typeVars ) {
+	// Start at the beginning, but the return argument may have been added.
+	auto arg = expr->args.begin();
+	if ( polyRetType ) ++arg;
+
 	for ( auto param : function->params ) {
 		assertf( arg != expr->args.end(),
@@ -928,8 +923,7 @@
 void CallAdapter::addInferredParams(
 		ast::ApplicationExpr * expr,
-		ast::vector<ast::Expr>::iterator arg,
+		ast::vector<ast::Expr> & extraArgs,
 		ast::FunctionType const * functionType,
 		TypeVarMap const & typeVars ) {
-	ast::vector<ast::Expr>::iterator cur = arg;
 	for ( auto assertion : functionType->assertions ) {
 		auto inferParam = expr->inferred.inferParams().find(
@@ -940,6 +934,5 @@
 		ast::ptr<ast::Expr> newExpr = ast::deepCopy( inferParam->second.expr );
 		boxParam( newExpr, assertion->result, typeVars );
-		cur = expr->args.insert( cur, newExpr.release() );
-		++cur;
+		extraArgs.emplace_back( newExpr.release() );
 	}
 }
@@ -1116,9 +1109,6 @@
 	);
 
-	for ( auto group : group_iterate( realType->assertions,
-			adapterType->assertions, adaptee->assertions ) ) {
-		auto assertArg = std::get<0>( group );
-		auto assertParam = std::get<1>( group );
-		auto assertReal = std::get<2>( group );
+	for ( auto const & [assertArg, assertParam, assertReal] : group_iterate(
+			realType->assertions, adapterType->assertions, adaptee->assertions ) ) {
 		adapteeApp->args.push_back( makeAdapterArg(
 			assertParam->var, assertArg->var->get_type(),
@@ -1977,7 +1967,6 @@
 	bool hasDynamicLayout = false;
 
-	for ( auto pair : group_iterate( baseParams, typeParams ) ) {
-		auto baseParam = std::get<0>( pair );
-		auto typeParam = std::get<1>( pair );
+	for ( auto const & [baseParam, typeParam] : group_iterate(
+			baseParams, typeParams ) ) {
 		if ( !baseParam->isComplete() ) continue;
 		ast::TypeExpr const * typeExpr = typeParam.as<ast::TypeExpr>();
Index: src/InitTweak/FixInit.cpp
===================================================================
--- src/InitTweak/FixInit.cpp	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/InitTweak/FixInit.cpp	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -1134,5 +1134,5 @@
 			ast::Expr * thisExpr = new ast::CastExpr(funcDecl->location, new ast::VariableExpr(funcDecl->location, thisParam ), thisParam->get_type()->stripReferences());
 			ast::Expr * memberDest = new ast::MemberExpr(funcDecl->location, field, thisExpr );
-			ast::ptr<ast::Stmt> callStmt = SymTab::genImplicitCall( srcParam, memberDest, loc, function->name, field, static_cast<SymTab::LoopDirection>(isCtor) );
+			const ast::Stmt * callStmt = SymTab::genImplicitCall( srcParam, memberDest, loc, function->name, field, static_cast<SymTab::LoopDirection>(isCtor) );
 
 			if ( callStmt ) {
Index: src/InitTweak/GenInit.cc
===================================================================
--- src/InitTweak/GenInit.cc	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/InitTweak/GenInit.cc	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -239,5 +239,5 @@
 					if ( varExpr->var == retVal ) return stmt;
 				}
-				ast::ptr<ast::Stmt> ctorStmt = genCtorDtor(
+				const ast::Stmt * ctorStmt = genCtorDtor(
 					retVal->location, "?{}", retVal, stmt->expr );
 				assertf( ctorStmt,
@@ -327,5 +327,5 @@
 void ManagedTypes::endScope() { managedTypes.endScope(); }
 
-ast::ptr<ast::Stmt> genCtorDtor (const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg) {
+const ast::Stmt * genCtorDtor( const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg ) {
 	assertf(objDecl, "genCtorDtor passed null objDecl");
 	InitExpander srcParam(arg);
Index: src/InitTweak/GenInit.h
===================================================================
--- src/InitTweak/GenInit.h	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/InitTweak/GenInit.h	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -33,5 +33,5 @@
 
 /// generates a single ctor/dtor statement using objDecl as the 'this' parameter and arg as the optional argument
-ast::ptr<ast::Stmt> genCtorDtor (const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg = nullptr);
+const ast::Stmt * genCtorDtor( const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg = nullptr );
 
 /// creates an appropriate ConstructorInit node which contains a constructor, destructor, and C-initializer
Index: src/Parser/DeclarationNode.cc
===================================================================
--- src/Parser/DeclarationNode.cc	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/Parser/DeclarationNode.cc	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 12:34:05 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Dec 14 19:05:17 2023
-// Update Count     : 1407
+// Last Modified On : Fri Feb 23 18:25:57 2024
+// Update Count     : 1533
 //
 
@@ -159,7 +159,8 @@
 
 	if ( ! attributes.empty() ) {
-		os << string( indent + 2, ' ' ) << "with attributes " << endl;
+		os << string( indent + 2, ' ' ) << "with attributes" << endl;
 		for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( attributes ) ) {
-			os << string( indent + 4, ' ' ) << attr->name.c_str() << endl;
+			os << string( indent + 4, ' ' );
+			ast::print( os, attr, indent + 2 );
 		} // for
 	} // if
@@ -537,14 +538,16 @@
 } // DeclarationNode::checkSpecifiers
 
-DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) {
+DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q, bool copyattr ) {
 	funcSpecs |= q->funcSpecs;
 	storageClasses |= q->storageClasses;
 
-	std::vector<ast::ptr<ast::Attribute>> tmp;
-	tmp.reserve( q->attributes.size() );
-	for ( auto const & attr : q->attributes ) {
-		tmp.emplace_back( ast::shallowCopy( attr.get() ) );
-	}
-	spliceBegin( attributes, tmp );
+	if ( copyattr ) {
+		std::vector<ast::ptr<ast::Attribute>> tmp;
+		tmp.reserve( q->attributes.size() );
+		for ( auto const & attr : q->attributes ) {
+			tmp.emplace_back( ast::shallowCopy( attr.get() ) );
+		} // for
+		spliceBegin( attributes, tmp );
+	} // if
 
 	return this;
@@ -681,13 +684,15 @@
 }
 
-DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) {
+DeclarationNode * DeclarationNode::addType( DeclarationNode * o, bool copyattr ) {
 	if ( o ) {
 		checkSpecifiers( o );
-		copySpecifiers( o );
+		copySpecifiers( o, copyattr );
 		if ( o->type ) {
 			if ( ! type ) {
 				if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) {
+					// Hide type information aggregate instances.
 					type = new TypeData( TypeData::AggregateInst );
-					type->aggInst.aggregate = o->type;
+					type->aggInst.aggregate = o->type;	// change ownership
+					type->aggInst.aggregate->aggregate.attributes.swap( o->attributes ); // change ownership					
 					if ( o->type->kind == TypeData::Aggregate ) {
 						type->aggInst.hoistType = o->type->aggregate.body;
@@ -700,5 +705,5 @@
 					type = o->type;
 				} // if
-				o->type = nullptr;
+				o->type = nullptr;						// change ownership
 			} else {
 				addTypeToType( o->type, type );
@@ -953,8 +958,8 @@
 }
 
-DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {
+DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o, bool copyattr ) {
 	if ( ! o ) return nullptr;
 
-	o->copySpecifiers( this );
+	o->copySpecifiers( this, copyattr );
 	if ( type ) {
 		TypeData * srcType = type;
@@ -999,4 +1004,7 @@
 			DeclarationNode * newnode = new DeclarationNode;
 			newnode->type = ret;
+			if ( ret->kind == TypeData::Aggregate ) {
+				newnode->attributes.swap( ret->aggregate.attributes );
+			} // if 
 			return newnode;
 		} // if
@@ -1110,8 +1118,8 @@
 					if ( extr->type->kind == TypeData::Aggregate ) {
 						// typedef struct { int A } B is the only case?
-						extracted_named = !extr->type->aggregate.anon;
+						extracted_named = ! extr->type->aggregate.anon;
 					} else if ( extr->type->kind == TypeData::Enum ) {
 						// typedef enum { A } B is the only case?
-						extracted_named = !extr->type->enumeration.anon;
+						extracted_named = ! extr->type->enumeration.anon;
 					} else {
 						extracted_named = true;
Index: src/Parser/DeclarationNode.h
===================================================================
--- src/Parser/DeclarationNode.h	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/Parser/DeclarationNode.h	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -9,7 +9,7 @@
 // Author           : Andrew Beach
 // Created On       : Wed Apr  5 11:38:00 2023
-// Last Modified By : Andrew Beach
-// Last Modified On : Wed Apr  5 11:55:00 2023
-// Update Count     : 0
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Sat Feb 17 09:24:12 2024
+// Update Count     : 4
 //
 
@@ -83,6 +83,6 @@
 	void checkQualifiers( const TypeData *, const TypeData * );
 	void checkSpecifiers( DeclarationNode * );
-	DeclarationNode * copySpecifiers( DeclarationNode * );
-	DeclarationNode * addType( DeclarationNode * );
+	DeclarationNode * copySpecifiers( DeclarationNode *, bool = true );
+	DeclarationNode * addType( DeclarationNode *, bool = true );
 	DeclarationNode * addTypedef();
 	DeclarationNode * addEnumBase( DeclarationNode * );
@@ -106,5 +106,5 @@
 
 	DeclarationNode * cloneType( std::string * newName );
-	DeclarationNode * cloneBaseType( DeclarationNode * newdecl );
+	DeclarationNode * cloneBaseType( DeclarationNode * newdecl, bool = true );
 
 	DeclarationNode * appendList( DeclarationNode * node ) {
Index: src/Parser/TypeData.cc
===================================================================
--- src/Parser/TypeData.cc	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/Parser/TypeData.cc	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 15:12:51 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Dec 14 18:59:12 2023
-// Update Count     : 684
+// Last Modified On : Fri Feb 23 08:58:30 2024
+// Update Count     : 734
 //
 
@@ -20,8 +20,10 @@
 
 #include "AST/Decl.hpp"            // for AggregateDecl, ObjectDecl, TypeDe...
+#include "AST/Attribute.hpp"       // for Attribute
 #include "AST/Init.hpp"            // for SingleInit, ListInit
 #include "AST/Print.hpp"           // for print
 #include "Common/SemanticError.h"  // for SemanticError
 #include "Common/utility.h"        // for splice, spliceBegin
+#include "Common/Iterate.hpp"      // for reverseIterate
 #include "Parser/ExpressionNode.h" // for ExpressionNode
 #include "Parser/StatementNode.h"  // for StatementNode
@@ -199,11 +201,12 @@
 		newtype->aggregate.kind = aggregate.kind;
 		newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr;
+		newtype->aggregate.parent = aggregate.parent ? new string( *aggregate.parent ) : nullptr;
 		newtype->aggregate.params = maybeCopy( aggregate.params );
 		newtype->aggregate.actuals = maybeCopy( aggregate.actuals );
 		newtype->aggregate.fields = maybeCopy( aggregate.fields );
+		newtype->aggregate.attributes = aggregate.attributes;
 		newtype->aggregate.body = aggregate.body;
 		newtype->aggregate.anon = aggregate.anon;
 		newtype->aggregate.tagged = aggregate.tagged;
-		newtype->aggregate.parent = aggregate.parent ? new string( *aggregate.parent ) : nullptr;
 		break;
 	case AggregateInst:
@@ -336,5 +339,12 @@
 		} // if
 		if ( aggregate.body ) {
-			os << string( indent + 2, ' ' ) << " with body" << endl;
+			os << string( indent + 2, ' ' ) << "with body" << endl;
+		} // if
+		if ( ! aggregate.attributes.empty() ) {
+			os << string( indent + 2, ' ' ) << "with attributes" << endl;
+			for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( aggregate.attributes ) ) {
+				os << string( indent + 4, ' ' );
+				ast::print( os, attr, indent + 2 );
+			} // for
 		} // if
 		break;
@@ -358,5 +368,5 @@
 		} // if
 		if ( enumeration.body ) {
-			os << string( indent + 2, ' ' ) << " with body" << endl;
+			os << string( indent + 2, ' ' ) << "with body" << endl;
 		} // if
 		if ( base ) {
@@ -1088,28 +1098,28 @@
 
 ast::BaseInstType * buildComAggInst(
-		const TypeData * type,
+		const TypeData * td,
 		std::vector<ast::ptr<ast::Attribute>> && attributes,
 		ast::Linkage::Spec linkage ) {
-	switch ( type->kind ) {
+	switch ( td->kind ) {
 	case TypeData::Enum:
-		if ( type->enumeration.body ) {
+		if ( td->enumeration.body ) {
 			ast::EnumDecl * typedecl =
-				buildEnum( type, std::move( attributes ), linkage );
+				buildEnum( td, std::move( attributes ), linkage );
 			return new ast::EnumInstType(
 				typedecl,
-				buildQualifiers( type )
+				buildQualifiers( td )
 			);
 		} else {
 			return new ast::EnumInstType(
-				*type->enumeration.name,
-				buildQualifiers( type )
+				*td->enumeration.name,
+				buildQualifiers( td )
 			);
 		} // if
 		break;
 	case TypeData::Aggregate:
-		if ( type->aggregate.body ) {
+		if ( td->aggregate.body ) {
 			ast::AggregateDecl * typedecl =
-				buildAggregate( type, std::move( attributes ), linkage );
-			switch ( type->aggregate.kind ) {
+				buildAggregate( td, std::move( attributes ), linkage );
+			switch ( td->aggregate.kind ) {
 			case ast::AggregateDecl::Struct:
 			case ast::AggregateDecl::Coroutine:
@@ -1118,10 +1128,10 @@
 				return new ast::StructInstType(
 					strict_dynamic_cast<ast::StructDecl *>( typedecl ),
-					buildQualifiers( type )
+					buildQualifiers( td )
 				);
 			case ast::AggregateDecl::Union:
 				return new ast::UnionInstType(
 					strict_dynamic_cast<ast::UnionDecl *>( typedecl ),
-					buildQualifiers( type )
+					buildQualifiers( td )
 				);
 			case ast::AggregateDecl::Trait:
@@ -1132,5 +1142,5 @@
 			} // switch
 		} else {
-			switch ( type->aggregate.kind ) {
+			switch ( td->aggregate.kind ) {
 			case ast::AggregateDecl::Struct:
 			case ast::AggregateDecl::Coroutine:
@@ -1138,16 +1148,16 @@
 			case ast::AggregateDecl::Thread:
 				return new ast::StructInstType(
-					*type->aggregate.name,
-					buildQualifiers( type )
+					*td->aggregate.name,
+					buildQualifiers( td )
 				);
 			case ast::AggregateDecl::Union:
 				return new ast::UnionInstType(
-					*type->aggregate.name,
-					buildQualifiers( type )
+					*td->aggregate.name,
+					buildQualifiers( td )
 				);
 			case ast::AggregateDecl::Trait:
 				return new ast::TraitInstType(
-					*type->aggregate.name,
-					buildQualifiers( type )
+					*td->aggregate.name,
+					buildQualifiers( td )
 				);
 			default:
Index: src/Parser/TypeData.h
===================================================================
--- src/Parser/TypeData.h	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/Parser/TypeData.h	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -9,7 +9,7 @@
 // Author           : Peter A. Buhr
 // Created On       : Sat May 16 15:18:36 2015
-// Last Modified By : Andrew Beach
-// Last Modified On : Wed Mar  1 10:44:00 2023
-// Update Count     : 206
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Thu Feb 22 16:30:31 2024
+// Update Count     : 210
 //
 
@@ -30,11 +30,12 @@
 		ast::AggregateDecl::Aggregate kind;
 		const std::string * name = nullptr;
+		const std::string * parent = nullptr;
 		DeclarationNode * params = nullptr;
 		ExpressionNode * actuals = nullptr;				// holds actual parameters later applied to AggInst
 		DeclarationNode * fields = nullptr;
+		std::vector<ast::ptr<ast::Attribute>> attributes;
 		bool body;
 		bool anon;
 		bool tagged;
-		const std::string * parent = nullptr;
 	};
 
Index: src/Parser/parser.yy
===================================================================
--- src/Parser/parser.yy	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/Parser/parser.yy	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -10,6 +10,6 @@
 // Created On       : Sat Sep  1 20:22:55 2001
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Sun Nov 26 13:18:06 2023
-// Update Count     : 6398
+// Last Modified On : Fri Feb 23 18:25:46 2024
+// Update Count     : 6484
 //
 
@@ -102,16 +102,36 @@
 
 DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) {
-	// distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__.
+	// Distribute type specifier across all declared variables, e.g., static, const, __attribute__.
 	assert( declList );
-	// printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
-	DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec );
-	// printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
-	// cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
-
+
+	// Do not distribute attributes for aggregates because the attributes surrounding the aggregate belong it not the
+	// variables in the declaration list, e.g.,
+	//
+	//   struct __attribute__(( aligned(128) )) S { ...
+	//   } v1 __attribute__(( aligned(64) )), v2 __attribute__(( aligned(32) )), v3;
+	//   struct S v4;
+	//
+	// v1 => 64, v2 =>32, v3 => 128, v2 => 128
+	//
+	// Anonymous aggregates are a special case because there is no aggregate to bind the attribute to; hence it floats
+	// to the declaration list.
+	//
+	//   struct __attribute__(( aligned(128) )) /*anonymous */ { ... } v1;
+	//
+	// v1 => 128
+
+	bool copyattr = ! (typeSpec->type && typeSpec->type->kind == TypeData::Aggregate && ! typeSpec->type->aggregate.anon );
+
+	// addType copies the type information for the aggregate instances from typeSpec into cl's aggInst.aggregate.
+	DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec ); // typeSpec IS DELETED!!!
+
+	// Start at second variable in declaration list and clone the type specifiers for each variable..
 	for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
-		cl->cloneBaseType( cur );
+		cl->cloneBaseType( cur, copyattr );				// cur is modified
 	} // for
-	declList->addType( cl );
-	// printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 );
+
+	// Add first variable in declaration list with hidden type information in aggInst.aggregate, which is used by
+	// extractType to recover the type for the aggregate instances.
+	declList->addType( cl, copyattr );					// cl IS DELETED!!!
 	return declList;
 } // distAttr
@@ -192,8 +212,7 @@
 		fieldList = DeclarationNode::newName( nullptr );
 	} // if
-//	return distAttr( typeSpec, fieldList );				// mark all fields in list
 
 	// printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 );
-	DeclarationNode * temp = distAttr( typeSpec, fieldList );				// mark all fields in list
+	DeclarationNode * temp = distAttr( typeSpec, fieldList ); // mark all fields in list
 	// printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 );
 	return temp;
@@ -761,6 +780,29 @@
 	| string_literal '`' identifier						// CFA, postfix call
 		{ $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); }
+
+		// SKULLDUGGERY: The typedef table used for parsing does not store fields in structures. To parse a qualified
+		// name, it is assumed all name-tokens after the first are identifiers, regardless of how the lexer identifies
+    	// them. For example:
+		//   
+		//   struct S;
+		//   forall(T) struct T;
+		//   union U;
+		//   enum E { S, T, E };
+		//   struct Z { int S, T, Z, E, U; };
+		//   void fred () {
+		//       Z z;
+		//       z.S;  // lexer returns S is TYPEDEFname
+		//       z.T;  // lexer returns T is TYPEGENname
+		//       z.Z;  // lexer returns Z is TYPEDEFname
+		//       z.U;  // lexer returns U is TYPEDEFname
+		//       z.E;  // lexer returns E is TYPEDEFname
+		//   }
 	| postfix_expression '.' identifier
 		{ $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
+	| postfix_expression '.' TYPEDEFname				// CFA, SKULLDUGGERY
+		{ $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
+	| postfix_expression '.' TYPEGENname				// CFA, SKULLDUGGERY
+		{ $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }
+
 	| postfix_expression '.' INTEGERconstant			// CFA, tuple index
 		{ $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); }
@@ -1039,7 +1081,6 @@
 	| logical_OR_expression '?' comma_expression ':' conditional_expression
 		{ $$ = new ExpressionNode( build_cond( yylloc, $1, $3, $5 ) ); }
-		// FIX ME: computes $1 twice
 	| logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
-		{ $$ = new ExpressionNode( build_cond( yylloc, $1, $1->clone(), $4 ) ); }
+		{ $$ = new ExpressionNode( build_cond( yylloc, $1, nullptr, $4 ) ); }
 	;
 
@@ -1856,6 +1897,5 @@
 declaration_list:
 	declaration
-	| declaration_list declaration
-		{ $$ = $1->appendList( $2 ); }
+	| declaration_list declaration		{ $$ = $1->appendList( $2 ); }
 	;
 
@@ -1890,10 +1930,4 @@
 declaration:											// old & new style declarations
 	c_declaration ';'
-		{
-			// printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );
-			// for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
-			//   printf( "\tattr %s\n", attr->name.c_str() );
-			// } // for
-		}
 	| cfa_declaration ';'								// CFA
 	| static_assert										// C11
@@ -2348,10 +2382,4 @@
 sue_declaration_specifier:								// struct, union, enum + storage class + type specifier
 	sue_type_specifier
-		{
-			// printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
-			// for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
-			//   printf( "\tattr %s\n", attr->name.c_str() );
-			// } // for
-		}
 	| declaration_qualifier_list sue_type_specifier
 		{ $$ = $2->addQualifiers( $1 ); }
@@ -2364,10 +2392,4 @@
 sue_type_specifier:										// struct, union, enum + type specifier
 	elaborated_type
-		{
-			// printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
-			// for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
-			//   printf( "\tattr %s\n", attr->name.c_str() );
-			// } // for
-		}
 	| type_qualifier_list
 		{ if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
@@ -2442,10 +2464,4 @@
 elaborated_type:										// struct, union, enum
 	aggregate_type
-		{
-			// printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
-			// for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
-			//   printf( "\tattr %s\n", attr->name.c_str() );
-			// } // for
-		}
 	| enum_type
 	;
@@ -2679,5 +2695,5 @@
 		{ $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
 	| ENUM attribute_list_opt '!' '{' enumerator_list comma_opt '}'	// invalid syntax rule
-		{ SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
+		{ SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
 	| ENUM attribute_list_opt identifier
 		{ typedefTable.makeTypedef( *$3, "enum_type 1" ); }
@@ -2694,5 +2710,5 @@
 		}
 	| ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // unqualified type name
-		{ SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
+		{ SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
 	| ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
 		{
@@ -2700,5 +2716,5 @@
 		}
 	| ENUM '(' ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}'	// invalid syntax rule
-		{ SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
+		{ SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }
 	| ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
 		{
@@ -3177,5 +3193,6 @@
 			// unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is
 			// disallowed at the moment.
-			if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) {
+			if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static &&
+				 $1->type && $1->type->kind == TypeData::AggregateInst ) {
 				if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) {
 					SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr;
Index: src/ResolvExpr/CandidateFinder.cpp
===================================================================
--- src/ResolvExpr/CandidateFinder.cpp	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/ResolvExpr/CandidateFinder.cpp	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -1018,5 +1018,5 @@
 					}
 
-					if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer);						
+					if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer);
 					else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type));
 				}
@@ -1283,5 +1283,5 @@
 						restructureCast( cand->expr, toType, castExpr->isGenerated ),
 						copy( cand->env ), std::move( open ), std::move( need ), cand->cost + thisCost);
-					// currently assertions are always resolved immediately so this should have no effect. 
+					// currently assertions are always resolved immediately so this should have no effect.
 					// if this somehow changes in the future (e.g. delayed by indeterminate return type)
 					// we may need to revisit the logic.
@@ -1618,13 +1618,16 @@
 	void Finder::postvisit( const ast::ConditionalExpr * conditionalExpr ) {
 		// candidates for condition
+		ast::ptr<ast::Expr> arg1 = notZeroExpr( conditionalExpr->arg1 );
 		CandidateFinder finder1( context, tenv );
-		ast::ptr<ast::Expr> arg1 = notZeroExpr( conditionalExpr->arg1 );
 		finder1.find( arg1, ResolveMode::withAdjustment() );
 		if ( finder1.candidates.empty() ) return;
 
 		// candidates for true result
+		// FIX ME: resolves and runs arg1 twice when arg2 is missing.
+		ast::Expr const * arg2 = conditionalExpr->arg2;
+		arg2 = arg2 ? arg2 : conditionalExpr->arg1.get();
 		CandidateFinder finder2( context, tenv );
 		finder2.allowVoid = true;
-		finder2.find( conditionalExpr->arg2, ResolveMode::withAdjustment() );
+		finder2.find( arg2, ResolveMode::withAdjustment() );
 		if ( finder2.candidates.empty() ) return;
 
@@ -1897,8 +1900,8 @@
 					CandidateRef newCand =
 						std::make_shared<Candidate>(
-							newExpr, copy( tenv ), ast::OpenVarSet{}, 
+							newExpr, copy( tenv ), ast::OpenVarSet{},
 							ast::AssertionSet{}, Cost::zero, cost
 						);
-					
+
 					if (newCand->expr->env) {
 						newCand->env.add(*newCand->expr->env);
Index: src/ResolvExpr/ResolveTypeof.cc
===================================================================
--- src/ResolvExpr/ResolveTypeof.cc	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/ResolvExpr/ResolveTypeof.cc	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -35,44 +35,43 @@
 
 struct ResolveTypeof : public ast::WithShortCircuiting {
-    const ResolveContext & context;
+	const ResolveContext & context;
 
-		ResolveTypeof( const ResolveContext & context ) :
-			context( context ) {}
+	ResolveTypeof( const ResolveContext & context ) : context( context ) {}
 
-		void previsit( const ast::TypeofType * ) { visit_children = false; }
+	void previsit( const ast::TypeofType * ) { visit_children = false; }
 
-        const ast::Type * postvisit( const ast::TypeofType * typeofType ) {
-        // pass on null expression
-            if ( ! typeofType->expr ) return typeofType;
+	const ast::Type * postvisit( const ast::TypeofType * typeofType ) {
+		// pass on null expression
+		if ( ! typeofType->expr ) return typeofType;
 
-            ast::ptr< ast::Type > newType;
-            if ( auto tyExpr = typeofType->expr.as< ast::TypeExpr >() ) {
-            // typeof wrapping type
-            newType = tyExpr->type;
-        } else {
-            // typeof wrapping expression
-            ast::TypeEnvironment dummy;
-            ast::ptr< ast::Expr > newExpr =
-                resolveInVoidContext( typeofType->expr, context, dummy );
-            assert( newExpr->result && ! newExpr->result->isVoid() );
-            newType = newExpr->result;
-        }
+		ast::ptr< ast::Type > newType;
+		if ( auto tyExpr = typeofType->expr.as< ast::TypeExpr >() ) {
+			// typeof wrapping type
+			newType = tyExpr->type;
+		} else {
+			// typeof wrapping expression
+			ast::TypeEnvironment dummy;
+			ast::ptr< ast::Expr > newExpr =
+				resolveInVoidContext( typeofType->expr, context, dummy );
+			assert( newExpr->result && ! newExpr->result->isVoid() );
+			newType = newExpr->result;
+		}
 
-        // clear qualifiers for base, combine with typeoftype quals regardless
-        if ( typeofType->kind == ast::TypeofType::Basetypeof ) {
-            // replace basetypeof(<enum>) by int
-				if ( newType.as< ast::EnumInstType >() ) {
-					newType = new ast::BasicType{
-						ast::BasicType::SignedInt, newType->qualifiers, copy(newType->attributes) };
-            }
-				reset_qualifiers(
-					newType,
-					( newType->qualifiers & ~ast::CV::EquivQualifiers ) | typeofType->qualifiers );
-        } else {
-				add_qualifiers( newType, typeofType->qualifiers );
-        }
+		// clear qualifiers for base, combine with typeoftype quals regardless
+		if ( typeofType->kind == ast::TypeofType::Basetypeof ) {
+			// replace basetypeof(<enum>) by int
+			if ( newType.as< ast::EnumInstType >() ) {
+				newType = new ast::BasicType(
+					ast::BasicType::SignedInt, newType->qualifiers, copy(newType->attributes) );
+			}
+			reset_qualifiers(
+				newType,
+				( newType->qualifiers & ~ast::CV::EquivQualifiers ) | typeofType->qualifiers );
+		} else {
+			add_qualifiers( newType, typeofType->qualifiers );
+		}
 
-        return newType.release();
-    }
+		return newType.release();
+	}
 };
 
@@ -111,83 +110,75 @@
 
 const ast::ObjectDecl * fixObjectType( const ast::ObjectDecl * decl , const ResolveContext & context ) {
-    if (decl->isTypeFixed) {
-        return decl;
-    }
+	if ( decl->isTypeFixed ) {
+		return decl;
+	}
 
-    auto mutDecl = mutate(decl);
-    fixObjectInit(decl, context);
-    {
-        auto resolvedType = resolveTypeof(decl->type, context);
-        resolvedType = fixArrayType(resolvedType, context);
-        mutDecl->type = resolvedType;
-    }
+	auto mutDecl = mutate(decl);
+	fixObjectInit(decl, context);
+	{
+		auto resolvedType = resolveTypeof(decl->type, context);
+		resolvedType = fixArrayType(resolvedType, context);
+		mutDecl->type = resolvedType;
+	}
 
-    // Do not mangle unnamed variables.
-    if (!mutDecl->name.empty()) {
-        mutDecl->mangleName = Mangle::mangle(mutDecl);
-    }
+	// Do not mangle unnamed variables.
+	if ( !mutDecl->name.empty() ) {
+		mutDecl->mangleName = Mangle::mangle(mutDecl);
+	}
 
-    mutDecl->type = renameTyVars(mutDecl->type, RenameMode::GEN_EXPR_ID);
-    mutDecl->isTypeFixed = true;
-    return mutDecl;
+	mutDecl->type = renameTyVars(mutDecl->type, RenameMode::GEN_EXPR_ID);
+	mutDecl->isTypeFixed = true;
+	return mutDecl;
 }
 
-const ast::ObjectDecl *fixObjectInit(const ast::ObjectDecl *decl,
-                                     const ResolveContext &context) {
-    if (decl->isTypeFixed) {
-        return decl;
-    }
+const ast::ObjectDecl *fixObjectInit(
+		const ast::ObjectDecl *decl, const ResolveContext &context) {
+	if ( decl->isTypeFixed ) {
+		return decl;
+	}
 
-    auto mutDecl = mutate(decl);
+	if ( auto listInit = decl->init.as<ast::ListInit>() ) {
+		for ( size_t k = 0; k < listInit->designations.size(); k++ ) {
+			const ast::Designation *des = listInit->designations[k].get();
+			// Desination here
+			ast::Designation * newDesignation = new ast::Designation(des->location);
+			std::deque<ast::ptr<ast::Expr>> newDesignators;
 
-    if ( auto mutListInit = mutDecl->init.as<ast::ListInit>() ) {
-        // std::list<ast::Designation *> newDesignations;        
-
-        for ( size_t k = 0; k < mutListInit->designations.size(); k++ ) {
-            const ast::Designation *des = mutListInit->designations[k].get();
-            // Desination here
-            ast::Designation * newDesignation = new ast::Designation(des->location);
-            std::deque<ast::ptr<ast::Expr>> newDesignators;
-
-            for ( ast::ptr<ast::Expr> designator : des->designators ) {
-                // Stupid flag variable for development, to be removed
-                // bool mutated = false;
-                if ( const ast::NameExpr * designatorName = designator.as<ast::NameExpr>() ) {
-                    auto candidates = context.symtab.lookupId(designatorName->name);
-                    // Does not work for the overloading case currently
-                    // assert( candidates.size() == 1 );
-                    if ( candidates.size() != 1 ) return mutDecl;
-                    auto candidate = candidates.at(0);
-                    if ( const ast::EnumInstType * enumInst = dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type())) {
-                        // determine that is an enumInst, swap it with its const value
-                        assert( candidates.size() == 1 );
-                        const ast::EnumDecl * baseEnum = enumInst->base;
-                        // Need to iterate over all enum value to find the initializer to swap
-                        for ( size_t m = 0; m < baseEnum->members.size(); ++m ) {
-                            const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>();
-                            if ( baseEnum->members.at(m)->name == designatorName->name ) {
-                                assert(mem);
-                                newDesignators.push_back( ast::ConstantExpr::from_int(designator->location, m) );
-                                // mutated = true;
-                                break;
-                            }
-                        }
-                    } else {
-                        newDesignators.push_back( des->designators.at(0) );
-                    }
-                } else {
-                    newDesignators.push_back( des->designators.at(0) );
-                }
-            }            
-            
-            newDesignation->designators = newDesignators;
-            mutListInit = ast::mutate_field_index(mutListInit, &ast::ListInit::designations, k, newDesignation);
-            
-        }
-    }
-    return mutDecl;
+			for ( ast::ptr<ast::Expr> designator : des->designators ) {
+				// Stupid flag variable for development, to be removed
+				if ( const ast::NameExpr * designatorName = designator.as<ast::NameExpr>() ) {
+					auto candidates = context.symtab.lookupId(designatorName->name);
+					// Does not work for the overloading case currently
+					// assert( candidates.size() == 1 );
+					if ( candidates.size() != 1 ) return decl;
+					auto candidate = candidates.at(0);
+					if ( const ast::EnumInstType * enumInst = dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type())) {
+						// determine that is an enumInst, swap it with its const value
+						assert( candidates.size() == 1 );
+						const ast::EnumDecl * baseEnum = enumInst->base;
+						// Need to iterate over all enum value to find the initializer to swap
+						for ( size_t m = 0; m < baseEnum->members.size(); ++m ) {
+							const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>();
+							if ( baseEnum->members.at(m)->name == designatorName->name ) {
+								assert( mem );
+								newDesignators.push_back( ast::ConstantExpr::from_int(designator->location, m) );
+								break;
+							}
+						}
+					} else {
+						newDesignators.push_back( des->designators.at(0) );
+					}
+				} else {
+					newDesignators.push_back( des->designators.at(0) );
+				}
+			}
+			newDesignation->designators = newDesignators;
+			listInit = ast::mutate_field_index(listInit, &ast::ListInit::designations, k, newDesignation);
+		}
+	}
+	return decl;
 }
 
-}  // namespace ResolvExpr
+} // namespace ResolvExpr
 
 // Local Variables: //
Index: src/ResolvExpr/Resolver.cc
===================================================================
--- src/ResolvExpr/Resolver.cc	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/ResolvExpr/Resolver.cc	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -50,1198 +50,1194 @@
 
 namespace ResolvExpr {
-	namespace {
-		/// Finds deleted expressions in an expression tree
-		struct DeleteFinder final : public ast::WithShortCircuiting, public ast::WithVisitorRef<DeleteFinder> {
-			const ast::DeletedExpr * result = nullptr;
-
-			void previsit( const ast::DeletedExpr * expr ) {
-				if ( result ) { visit_children = false; }
-				else { result = expr; }
+
+namespace {
+	/// Finds deleted expressions in an expression tree
+	struct DeleteFinder final : public ast::WithShortCircuiting, public ast::WithVisitorRef<DeleteFinder> {
+		const ast::DeletedExpr * result = nullptr;
+
+		void previsit( const ast::DeletedExpr * expr ) {
+			if ( result ) { visit_children = false; }
+			else { result = expr; }
+		}
+
+		void previsit( const ast::Expr * expr ) {
+			if ( result ) { visit_children = false; }
+			if (expr->inferred.hasParams()) {
+				for (auto & imp : expr->inferred.inferParams() ) {
+					imp.second.expr->accept(*visitor);
+				}
 			}
-
-			void previsit( const ast::Expr * expr ) {
-				if ( result ) { visit_children = false; }
-				if (expr->inferred.hasParams()) {
-					for (auto & imp : expr->inferred.inferParams() ) {
-						imp.second.expr->accept(*visitor);
+		}
+	};
+
+	struct ResolveDesignators final : public ast::WithShortCircuiting {
+		ResolveContext& context;
+		bool result = false;
+
+		ResolveDesignators( ResolveContext& _context ): context(_context) {};
+
+		void previsit( const ast::Node * ) {
+			// short circuit if we already know there are designations
+			if ( result ) visit_children = false;
+		}
+
+		void previsit( const ast::Designation * des ) {
+			if ( result ) visit_children = false;
+			else if ( ! des->designators.empty() ) {
+				if ( (des->designators.size() == 1) ) {
+					const ast::Expr * designator = des->designators.at(0);
+					if ( const ast::NameExpr * designatorName = dynamic_cast<const ast::NameExpr *>(designator) ) {
+						auto candidates = context.symtab.lookupId(designatorName->name);
+						for ( auto candidate : candidates ) {
+							if ( dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type()) ) {
+								result = true;
+								break;
+							}
+						}
+					}
+				}
+				visit_children = false;
+			}
+		}
+	};
+} // anonymous namespace
+
+/// Check if this expression is or includes a deleted expression
+const ast::DeletedExpr * findDeletedExpr( const ast::Expr * expr ) {
+	return ast::Pass<DeleteFinder>::read( expr );
+}
+
+namespace {
+	/// always-accept candidate filter
+	bool anyCandidate( const Candidate & ) { return true; }
+
+	/// Calls the CandidateFinder and finds the single best candidate
+	CandidateRef findUnfinishedKindExpression(
+		const ast::Expr * untyped, const ResolveContext & context, const std::string & kind,
+		std::function<bool(const Candidate &)> pred = anyCandidate, ResolveMode mode = {}
+	) {
+		if ( ! untyped ) return nullptr;
+
+		// xxx - this isn't thread-safe, but should work until we parallelize the resolver
+		static unsigned recursion_level = 0;
+
+		++recursion_level;
+		ast::TypeEnvironment env;
+		CandidateFinder finder( context, env );
+		finder.allowVoid = true;
+		finder.find( untyped, recursion_level == 1 ? mode.atTopLevel() : mode );
+		--recursion_level;
+
+		// produce a filtered list of candidates
+		CandidateList candidates;
+		for ( auto & cand : finder.candidates ) {
+			if ( pred( *cand ) ) { candidates.emplace_back( cand ); }
+		}
+
+		// produce invalid error if no candidates
+		if ( candidates.empty() ) {
+			SemanticError( untyped,
+				toString( "No reasonable alternatives for ", kind, (kind != "" ? " " : ""),
+				"expression: ") );
+		}
+
+		// search for cheapest candidate
+		CandidateList winners;
+		bool seen_undeleted = false;
+		for ( CandidateRef & cand : candidates ) {
+			int c = winners.empty() ? -1 : cand->cost.compare( winners.front()->cost );
+
+			if ( c > 0 ) continue;  // skip more expensive than winner
+
+			if ( c < 0 ) {
+				// reset on new cheapest
+				seen_undeleted = ! findDeletedExpr( cand->expr );
+				winners.clear();
+			} else /* if ( c == 0 ) */ {
+				if ( findDeletedExpr( cand->expr ) ) {
+					// skip deleted expression if already seen one equivalent-cost not
+					if ( seen_undeleted ) continue;
+				} else if ( ! seen_undeleted ) {
+					// replace list of equivalent-cost deleted expressions with one non-deleted
+					winners.clear();
+					seen_undeleted = true;
+				}
+			}
+
+			winners.emplace_back( std::move( cand ) );
+		}
+
+		// promote candidate.cvtCost to .cost
+		// promoteCvtCost( winners );
+
+		// produce ambiguous errors, if applicable
+		if ( winners.size() != 1 ) {
+			std::ostringstream stream;
+			stream << "Cannot choose between " << winners.size() << " alternatives for "
+				<< kind << (kind != "" ? " " : "") << "expression\n";
+			ast::print( stream, untyped );
+			stream << " Alternatives are:\n";
+			print( stream, winners, 1 );
+			SemanticError( untyped->location, stream.str() );
+		}
+
+		// single selected choice
+		CandidateRef & choice = winners.front();
+
+		// fail on only expression deleted
+		if ( ! seen_undeleted ) {
+			SemanticError( untyped->location, choice->expr.get(), "Unique best alternative "
+			"includes deleted identifier in " );
+		}
+
+		return std::move( choice );
+	}
+
+	/// Strips extraneous casts out of an expression
+	struct StripCasts final {
+		const ast::Expr * postvisit( const ast::CastExpr * castExpr ) {
+			if (
+				castExpr->isGenerated == ast::GeneratedCast
+				&& typesCompatible( castExpr->arg->result, castExpr->result )
+			) {
+				// generated cast is the same type as its argument, remove it after keeping env
+				return ast::mutate_field(
+					castExpr->arg.get(), &ast::Expr::env, castExpr->env );
+			}
+			return castExpr;
+		}
+
+		static void strip( ast::ptr< ast::Expr > & expr ) {
+			ast::Pass< StripCasts > stripper;
+			expr = expr->accept( stripper );
+		}
+	};
+
+	/// Swaps argument into expression pointer, saving original environment
+	void swap_and_save_env( ast::ptr< ast::Expr > & expr, const ast::Expr * newExpr ) {
+		ast::ptr< ast::TypeSubstitution > env = expr->env;
+		expr.set_and_mutate( newExpr )->env = env;
+	}
+
+	/// Removes cast to type of argument (unlike StripCasts, also handles non-generated casts)
+	void removeExtraneousCast( ast::ptr<ast::Expr> & expr ) {
+		if ( const ast::CastExpr * castExpr = expr.as< ast::CastExpr >() ) {
+			if ( typesCompatible( castExpr->arg->result, castExpr->result ) ) {
+				// cast is to the same type as its argument, remove it
+				swap_and_save_env( expr, castExpr->arg );
+			}
+		}
+	}
+
+} // anonymous namespace
+
+/// Establish post-resolver invariants for expressions
+void finishExpr(
+	ast::ptr< ast::Expr > & expr, const ast::TypeEnvironment & env,
+	const ast::TypeSubstitution * oldenv = nullptr
+) {
+	// set up new type substitution for expression
+	ast::ptr< ast::TypeSubstitution > newenv =
+		 oldenv ? oldenv : new ast::TypeSubstitution{};
+	env.writeToSubstitution( *newenv.get_and_mutate() );
+	expr.get_and_mutate()->env = std::move( newenv );
+	// remove unncecessary casts
+	StripCasts::strip( expr );
+}
+
+ast::ptr< ast::Expr > resolveInVoidContext(
+	const ast::Expr * expr, const ResolveContext & context,
+	ast::TypeEnvironment & env
+) {
+	assertf( expr, "expected a non-null expression" );
+
+	// set up and resolve expression cast to void
+	ast::ptr< ast::CastExpr > untyped = new ast::CastExpr{ expr };
+	CandidateRef choice = findUnfinishedKindExpression(
+		untyped, context, "", anyCandidate, ResolveMode::withAdjustment() );
+
+	// a cast expression has either 0 or 1 interpretations (by language rules);
+	// if 0, an exception has already been thrown, and this code will not run
+	const ast::CastExpr * castExpr = choice->expr.strict_as< ast::CastExpr >();
+	env = std::move( choice->env );
+
+	return castExpr->arg;
+}
+
+/// Resolve `untyped` to the expression whose candidate is the best match for a `void`
+/// context.
+ast::ptr< ast::Expr > findVoidExpression(
+	const ast::Expr * untyped, const ResolveContext & context
+) {
+	ast::TypeEnvironment env;
+	ast::ptr< ast::Expr > newExpr = resolveInVoidContext( untyped, context, env );
+	finishExpr( newExpr, env, untyped->env );
+	return newExpr;
+}
+
+namespace {
+	/// resolve `untyped` to the expression whose candidate satisfies `pred` with the
+	/// lowest cost, returning the resolved version
+	ast::ptr< ast::Expr > findKindExpression(
+		const ast::Expr * untyped, const ResolveContext & context,
+		std::function<bool(const Candidate &)> pred = anyCandidate,
+		const std::string & kind = "", ResolveMode mode = {}
+	) {
+		if ( ! untyped ) return {};
+		CandidateRef choice =
+			findUnfinishedKindExpression( untyped, context, kind, pred, mode );
+		ResolvExpr::finishExpr( choice->expr, choice->env, untyped->env );
+		return std::move( choice->expr );
+	}
+
+	/// Resolve `untyped` to the single expression whose candidate is the best match
+	ast::ptr< ast::Expr > findSingleExpression(
+		const ast::Expr * untyped, const ResolveContext & context
+	) {
+		Stats::ResolveTime::start( untyped );
+		auto res = findKindExpression( untyped, context );
+		Stats::ResolveTime::stop();
+		return res;
+	}
+} // anonymous namespace
+
+ast::ptr< ast::Expr > findSingleExpression(
+	const ast::Expr * untyped, const ast::Type * type,
+	const ResolveContext & context
+) {
+	assert( untyped && type );
+	ast::ptr< ast::Expr > castExpr = new ast::CastExpr{ untyped, type };
+	ast::ptr< ast::Expr > newExpr = findSingleExpression( castExpr, context );
+	removeExtraneousCast( newExpr );
+	return newExpr;
+}
+
+namespace {
+	bool structOrUnion( const Candidate & i ) {
+		const ast::Type * t = i.expr->result->stripReferences();
+		return dynamic_cast< const ast::StructInstType * >( t ) || dynamic_cast< const ast::UnionInstType * >( t );
+	}
+	/// Predicate for "Candidate has integral type"
+	bool hasIntegralType( const Candidate & i ) {
+		const ast::Type * type = i.expr->result;
+
+		if ( auto bt = dynamic_cast< const ast::BasicType * >( type ) ) {
+			return bt->isInteger();
+		} else if (
+			dynamic_cast< const ast::EnumInstType * >( type )
+			|| dynamic_cast< const ast::ZeroType * >( type )
+			|| dynamic_cast< const ast::OneType * >( type )
+		) {
+			return true;
+		} else return false;
+	}
+
+	/// Resolve `untyped` as an integral expression, returning the resolved version
+	ast::ptr< ast::Expr > findIntegralExpression(
+		const ast::Expr * untyped, const ResolveContext & context
+	) {
+		return findKindExpression( untyped, context, hasIntegralType, "condition" );
+	}
+
+	/// check if a type is a character type
+	bool isCharType( const ast::Type * t ) {
+		if ( auto bt = dynamic_cast< const ast::BasicType * >( t ) ) {
+			return bt->kind == ast::BasicType::Char
+				|| bt->kind == ast::BasicType::SignedChar
+				|| bt->kind == ast::BasicType::UnsignedChar;
+		}
+		return false;
+	}
+
+	/// Advance a type itertor to the next mutex parameter
+	template<typename Iter>
+	inline bool nextMutex( Iter & it, const Iter & end ) {
+		while ( it != end && ! (*it)->is_mutex() ) { ++it; }
+		return it != end;
+	}
+}
+
+class Resolver final
+: public ast::WithSymbolTable, public ast::WithGuards,
+  public ast::WithVisitorRef<Resolver>, public ast::WithShortCircuiting,
+  public ast::WithStmtsToAdd<> {
+
+	ast::ptr< ast::Type > functionReturn = nullptr;
+	ast::CurrentObject currentObject;
+	// for work previously in GenInit
+	static InitTweak::ManagedTypes managedTypes;
+	ResolveContext context;
+
+	bool inEnumDecl = false;
+
+public:
+	static size_t traceId;
+	Resolver( const ast::TranslationGlobal & global ) :
+		ast::WithSymbolTable(ast::SymbolTable::ErrorDetection::ValidateOnAdd),
+		context{ symtab, global } {}
+	Resolver( const ResolveContext & context ) :
+		ast::WithSymbolTable{ context.symtab },
+		context{ symtab, context.global } {}
+
+	const ast::FunctionDecl * previsit( const ast::FunctionDecl * );
+	const ast::FunctionDecl * postvisit( const ast::FunctionDecl * );
+	const ast::ObjectDecl * previsit( const ast::ObjectDecl * );
+	void previsit( const ast::AggregateDecl * );
+	void previsit( const ast::StructDecl * );
+	void previsit( const ast::EnumDecl * );
+	const ast::StaticAssertDecl * previsit( const ast::StaticAssertDecl * );
+
+	const ast::ArrayType * previsit( const ast::ArrayType * );
+	const ast::PointerType * previsit( const ast::PointerType * );
+
+	const ast::ExprStmt *        previsit( const ast::ExprStmt * );
+	const ast::AsmExpr *         previsit( const ast::AsmExpr * );
+	const ast::AsmStmt *         previsit( const ast::AsmStmt * );
+	const ast::IfStmt *          previsit( const ast::IfStmt * );
+	const ast::WhileDoStmt *     previsit( const ast::WhileDoStmt * );
+	const ast::ForStmt *         previsit( const ast::ForStmt * );
+	const ast::SwitchStmt *      previsit( const ast::SwitchStmt * );
+	const ast::CaseClause *      previsit( const ast::CaseClause * );
+	const ast::BranchStmt *      previsit( const ast::BranchStmt * );
+	const ast::ReturnStmt *      previsit( const ast::ReturnStmt * );
+	const ast::ThrowStmt *       previsit( const ast::ThrowStmt * );
+	const ast::CatchClause *     previsit( const ast::CatchClause * );
+	const ast::CatchClause *     postvisit( const ast::CatchClause * );
+	const ast::WaitForStmt *     previsit( const ast::WaitForStmt * );
+	const ast::WithStmt *        previsit( const ast::WithStmt * );
+
+	const ast::SingleInit *      previsit( const ast::SingleInit * );
+	const ast::ListInit *        previsit( const ast::ListInit * );
+	const ast::ConstructorInit * previsit( const ast::ConstructorInit * );
+
+	void resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd);
+
+	void beginScope() { managedTypes.beginScope(); }
+	void endScope() { managedTypes.endScope(); }
+	bool on_error(ast::ptr<ast::Decl> & decl);
+};
+// size_t Resolver::traceId = Stats::Heap::new_stacktrace_id("Resolver");
+
+InitTweak::ManagedTypes Resolver::managedTypes;
+
+void resolve( ast::TranslationUnit& translationUnit ) {
+	ast::Pass< Resolver >::run( translationUnit, translationUnit.global );
+}
+
+ast::ptr< ast::Init > resolveCtorInit(
+	const ast::ConstructorInit * ctorInit, const ResolveContext & context
+) {
+	assert( ctorInit );
+	ast::Pass< Resolver > resolver( context );
+	return ctorInit->accept( resolver );
+}
+
+const ast::Expr * resolveStmtExpr(
+	const ast::StmtExpr * stmtExpr, const ResolveContext & context
+) {
+	assert( stmtExpr );
+	ast::Pass< Resolver > resolver( context );
+	auto ret = mutate(stmtExpr->accept(resolver));
+	strict_dynamic_cast< ast::StmtExpr * >( ret )->computeResult();
+	return ret;
+}
+
+namespace {
+	const ast::Attribute * handleAttribute(const CodeLocation & loc, const ast::Attribute * attr, const ResolveContext & context) {
+		std::string name = attr->normalizedName();
+		if (name == "constructor" || name == "destructor") {
+			if (attr->params.size() == 1) {
+				auto arg = attr->params.front();
+				auto resolved = ResolvExpr::findSingleExpression( arg, new ast::BasicType( ast::BasicType::LongLongSignedInt ), context );
+				auto result = eval(arg);
+
+				auto mutAttr = mutate(attr);
+				mutAttr->params.front() = resolved;
+				if (! result.hasKnownValue) {
+					SemanticWarning(loc, Warning::GccAttributes,
+						toCString( name, " priorities must be integers from 0 to 65535 inclusive: ", arg ) );
+				}
+				else {
+					auto priority = result.knownValue;
+					if (priority < 101) {
+						SemanticWarning(loc, Warning::GccAttributes,
+							toCString( name, " priorities from 0 to 100 are reserved for the implementation" ) );
+					} else if (priority < 201 && ! buildingLibrary()) {
+						SemanticWarning(loc, Warning::GccAttributes,
+							toCString( name, " priorities from 101 to 200 are reserved for the implementation" ) );
+					}
+				}
+				return mutAttr;
+			} else if (attr->params.size() > 1) {
+				SemanticWarning(loc, Warning::GccAttributes, toCString( "too many arguments to ", name, " attribute" ) );
+			} else {
+				SemanticWarning(loc, Warning::GccAttributes, toCString( "too few arguments to ", name, " attribute" ) );
+			}
+		}
+		return attr;
+	}
+}
+
+const ast::FunctionDecl * Resolver::previsit( const ast::FunctionDecl * functionDecl ) {
+	GuardValue( functionReturn );
+
+	assert (functionDecl->unique());
+	if (!functionDecl->has_body() && !functionDecl->withExprs.empty()) {
+		SemanticError(functionDecl->location, functionDecl, "Function without body has with declarations");
+	}
+
+	if (!functionDecl->isTypeFixed) {
+		auto mutDecl = mutate(functionDecl);
+		auto mutType = mutDecl->type.get_and_mutate();
+
+		for (auto & attr: mutDecl->attributes) {
+			attr = handleAttribute(mutDecl->location, attr, context );
+		}
+
+		// handle assertions
+
+		symtab.enterScope();
+		mutType->forall.clear();
+		mutType->assertions.clear();
+		for (auto & typeParam : mutDecl->type_params) {
+			symtab.addType(typeParam);
+			mutType->forall.emplace_back(new ast::TypeInstType(typeParam));
+		}
+		for (auto & asst : mutDecl->assertions) {
+			asst = fixObjectType(asst.strict_as<ast::ObjectDecl>(), context);
+			symtab.addId(asst);
+			mutType->assertions.emplace_back(new ast::VariableExpr(functionDecl->location, asst));
+		}
+
+		// temporarily adds params to symbol table.
+		// actual scoping rules for params and withexprs differ - see Pass::visit(FunctionDecl)
+
+		std::vector<ast::ptr<ast::Type>> paramTypes;
+		std::vector<ast::ptr<ast::Type>> returnTypes;
+
+		for (auto & param : mutDecl->params) {
+			param = fixObjectType(param.strict_as<ast::ObjectDecl>(), context);
+			symtab.addId(param);
+			paramTypes.emplace_back(param->get_type());
+		}
+		for (auto & ret : mutDecl->returns) {
+			ret = fixObjectType(ret.strict_as<ast::ObjectDecl>(), context);
+			returnTypes.emplace_back(ret->get_type());
+		}
+		// since function type in decl is just a view of param types, need to update that as well
+		mutType->params = std::move(paramTypes);
+		mutType->returns = std::move(returnTypes);
+
+		auto renamedType = strict_dynamic_cast<const ast::FunctionType *>(renameTyVars(mutType, RenameMode::GEN_EXPR_ID));
+
+		std::list<ast::ptr<ast::Stmt>> newStmts;
+		resolveWithExprs (mutDecl->withExprs, newStmts);
+
+		if (mutDecl->stmts) {
+			auto mutStmt = mutDecl->stmts.get_and_mutate();
+			mutStmt->kids.splice(mutStmt->kids.begin(), std::move(newStmts));
+			mutDecl->stmts = mutStmt;
+		}
+
+		symtab.leaveScope();
+
+		mutDecl->type = renamedType;
+		mutDecl->mangleName = Mangle::mangle(mutDecl);
+		mutDecl->isTypeFixed = true;
+		functionDecl = mutDecl;
+	}
+	managedTypes.handleDWT(functionDecl);
+
+	functionReturn = extractResultType( functionDecl->type );
+	return functionDecl;
+}
+
+const ast::FunctionDecl * Resolver::postvisit( const ast::FunctionDecl * functionDecl ) {
+	// default value expressions have an environment which shouldn't be there and trips up
+	// later passes.
+	assert( functionDecl->unique() );
+	ast::FunctionType * mutType = mutate( functionDecl->type.get() );
+
+	for ( unsigned i = 0 ; i < mutType->params.size() ; ++i ) {
+		if ( const ast::ObjectDecl * obj = mutType->params[i].as< ast::ObjectDecl >() ) {
+			if ( const ast::SingleInit * init = obj->init.as< ast::SingleInit >() ) {
+				if ( init->value->env == nullptr ) continue;
+				// clone initializer minus the initializer environment
+				auto mutParam = mutate( mutType->params[i].strict_as< ast::ObjectDecl >() );
+				auto mutInit = mutate( mutParam->init.strict_as< ast::SingleInit >() );
+				auto mutValue = mutate( mutInit->value.get() );
+
+				mutValue->env = nullptr;
+				mutInit->value = mutValue;
+				mutParam->init = mutInit;
+				mutType->params[i] = mutParam;
+
+				assert( ! mutType->params[i].strict_as< ast::ObjectDecl >()->init.strict_as< ast::SingleInit >()->value->env);
+			}
+		}
+	}
+	mutate_field(functionDecl, &ast::FunctionDecl::type, mutType);
+	return functionDecl;
+}
+
+const ast::ObjectDecl * Resolver::previsit( const ast::ObjectDecl * objectDecl ) {
+	// To handle initialization of routine pointers [e.g. int (*fp)(int) = foo()],
+	// class-variable `initContext` is changed multiple times because the LHS is analyzed
+	// twice. The second analysis changes `initContext` because a function type can contain
+	// object declarations in the return and parameter types. Therefore each value of
+	// `initContext` is retained so the type on the first analysis is preserved and used for
+	// selecting the RHS.
+	GuardValue( currentObject );
+
+	if ( inEnumDecl && dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() ) ) {
+		// enumerator initializers should not use the enum type to initialize, since the
+		// enum type is still incomplete at this point. Use `int` instead.
+
+		if ( auto enumBase = dynamic_cast< const ast::EnumInstType * >
+			( objectDecl->get_type() )->base->base ) {
+			objectDecl = fixObjectType( objectDecl, context );
+			currentObject = ast::CurrentObject{
+				objectDecl->location,
+				enumBase
+			};
+		} else {
+			objectDecl = fixObjectType( objectDecl, context );
+			currentObject = ast::CurrentObject{
+				objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
+		}
+	} else {
+		if ( !objectDecl->isTypeFixed ) {
+			auto newDecl = fixObjectType(objectDecl, context);
+			auto mutDecl = mutate(newDecl);
+
+			// generate CtorInit wrapper when necessary.
+			// in certain cases, fixObjectType is called before reaching
+			// this object in visitor pass, thus disabling CtorInit codegen.
+			// this happens on aggregate members and function parameters.
+			if ( InitTweak::tryConstruct( mutDecl ) && ( managedTypes.isManaged( mutDecl ) || ((! isInFunction() || mutDecl->storage.is_static ) && ! InitTweak::isConstExpr( mutDecl->init ) ) ) ) {
+				// constructed objects cannot be designated
+				if ( InitTweak::isDesignated( mutDecl->init ) ) {
+					ast::Pass<ResolveDesignators> res( context );
+					maybe_accept( mutDecl->init.get(), res );
+					if ( !res.core.result ) {
+						SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object.\n"
+									   "If this is really what you want, initialize with @=." );
+					}
+				}
+				// constructed objects should not have initializers nested too deeply
+				if ( ! InitTweak::checkInitDepth( mutDecl ) ) SemanticError( mutDecl, "Managed object's initializer is too deep " );
+
+				mutDecl->init = InitTweak::genCtorInit( mutDecl->location, mutDecl );
+			}
+
+			objectDecl = mutDecl;
+		}
+		currentObject = ast::CurrentObject{ objectDecl->location, objectDecl->get_type() };
+	}
+
+	return objectDecl;
+}
+
+void Resolver::previsit( const ast::AggregateDecl * _aggDecl ) {
+	auto aggDecl = mutate(_aggDecl);
+	assertf(aggDecl == _aggDecl, "type declarations must be unique");
+
+	for (auto & member: aggDecl->members) {
+		// nested type decls are hoisted already. no need to do anything
+		if (auto obj = member.as<ast::ObjectDecl>()) {
+			member = fixObjectType(obj, context);
+		}
+	}
+}
+
+void Resolver::previsit( const ast::StructDecl * structDecl ) {
+	previsit(static_cast<const ast::AggregateDecl *>(structDecl));
+	managedTypes.handleStruct(structDecl);
+}
+
+void Resolver::previsit( const ast::EnumDecl * ) {
+	// in case we decide to allow nested enums
+	GuardValue( inEnumDecl );
+	inEnumDecl = true;
+	// don't need to fix types for enum fields
+}
+
+const ast::StaticAssertDecl * Resolver::previsit(
+	const ast::StaticAssertDecl * assertDecl
+) {
+	return ast::mutate_field(
+		assertDecl, &ast::StaticAssertDecl::cond,
+		findIntegralExpression( assertDecl->cond, context ) );
+}
+
+template< typename PtrType >
+const PtrType * handlePtrType( const PtrType * type, const ResolveContext & context ) {
+	if ( type->dimension ) {
+		const ast::Type * sizeType = context.global.sizeType.get();
+		ast::ptr< ast::Expr > dimension = findSingleExpression( type->dimension, sizeType, context );
+		assertf(dimension->env->empty(), "array dimension expr has nonempty env");
+		dimension.get_and_mutate()->env = nullptr;
+		ast::mutate_field( type, &PtrType::dimension, dimension );
+	}
+	return type;
+}
+
+const ast::ArrayType * Resolver::previsit( const ast::ArrayType * at ) {
+	return handlePtrType( at, context );
+}
+
+const ast::PointerType * Resolver::previsit( const ast::PointerType * pt ) {
+	return handlePtrType( pt, context );
+}
+
+const ast::ExprStmt * Resolver::previsit( const ast::ExprStmt * exprStmt ) {
+	visit_children = false;
+	assertf( exprStmt->expr, "ExprStmt has null expression in resolver" );
+
+	return ast::mutate_field(
+		exprStmt, &ast::ExprStmt::expr, findVoidExpression( exprStmt->expr, context ) );
+}
+
+const ast::AsmExpr * Resolver::previsit( const ast::AsmExpr * asmExpr ) {
+	visit_children = false;
+
+	asmExpr = ast::mutate_field(
+		asmExpr, &ast::AsmExpr::operand, findVoidExpression( asmExpr->operand, context ) );
+
+	return asmExpr;
+}
+
+const ast::AsmStmt * Resolver::previsit( const ast::AsmStmt * asmStmt ) {
+	visitor->maybe_accept( asmStmt, &ast::AsmStmt::input );
+	visitor->maybe_accept( asmStmt, &ast::AsmStmt::output );
+	visit_children = false;
+	return asmStmt;
+}
+
+const ast::IfStmt * Resolver::previsit( const ast::IfStmt * ifStmt ) {
+	return ast::mutate_field(
+		ifStmt, &ast::IfStmt::cond, findIntegralExpression( ifStmt->cond, context ) );
+}
+
+const ast::WhileDoStmt * Resolver::previsit( const ast::WhileDoStmt * whileDoStmt ) {
+	return ast::mutate_field(
+		whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, context ) );
+}
+
+const ast::ForStmt * Resolver::previsit( const ast::ForStmt * forStmt ) {
+	if ( forStmt->cond ) {
+		forStmt = ast::mutate_field(
+			forStmt, &ast::ForStmt::cond, findIntegralExpression( forStmt->cond, context ) );
+	}
+
+	if ( forStmt->inc ) {
+		forStmt = ast::mutate_field(
+			forStmt, &ast::ForStmt::inc, findVoidExpression( forStmt->inc, context ) );
+	}
+
+	return forStmt;
+}
+
+const ast::SwitchStmt * Resolver::previsit( const ast::SwitchStmt * switchStmt ) {
+	GuardValue( currentObject );
+	switchStmt = ast::mutate_field(
+		switchStmt, &ast::SwitchStmt::cond,
+		findIntegralExpression( switchStmt->cond, context ) );
+	currentObject = ast::CurrentObject{ switchStmt->location, switchStmt->cond->result };
+	return switchStmt;
+}
+
+const ast::CaseClause * Resolver::previsit( const ast::CaseClause * caseStmt ) {
+	if ( caseStmt->cond ) {
+		std::deque< ast::InitAlternative > initAlts = currentObject.getOptions();
+		assertf( initAlts.size() == 1, "SwitchStmt did not correctly resolve an integral "
+			"expression." );
+
+		ast::ptr< ast::Expr > untyped =
+			new ast::CastExpr{ caseStmt->location, caseStmt->cond, initAlts.front().type };
+		ast::ptr< ast::Expr > newExpr = findSingleExpression( untyped, context );
+
+		// case condition cannot have a cast in C, so it must be removed here, regardless of
+		// whether it would perform a conversion.
+		if ( const ast::CastExpr * castExpr = newExpr.as< ast::CastExpr >() ) {
+			swap_and_save_env( newExpr, castExpr->arg );
+		}
+
+		caseStmt = ast::mutate_field( caseStmt, &ast::CaseClause::cond, newExpr );
+	}
+	return caseStmt;
+}
+
+const ast::BranchStmt * Resolver::previsit( const ast::BranchStmt * branchStmt ) {
+	visit_children = false;
+	// must resolve the argument of a computed goto
+	if ( branchStmt->kind == ast::BranchStmt::Goto && branchStmt->computedTarget ) {
+		// computed goto argument is void*
+		ast::ptr< ast::Type > target = new ast::PointerType{ new ast::VoidType{} };
+		branchStmt = ast::mutate_field(
+			branchStmt, &ast::BranchStmt::computedTarget,
+			findSingleExpression( branchStmt->computedTarget, target, context ) );
+	}
+	return branchStmt;
+}
+
+const ast::ReturnStmt * Resolver::previsit( const ast::ReturnStmt * returnStmt ) {
+	visit_children = false;
+	if ( returnStmt->expr ) {
+		returnStmt = ast::mutate_field(
+			returnStmt, &ast::ReturnStmt::expr,
+			findSingleExpression( returnStmt->expr, functionReturn, context ) );
+	}
+	return returnStmt;
+}
+
+const ast::ThrowStmt * Resolver::previsit( const ast::ThrowStmt * throwStmt ) {
+	visit_children = false;
+	if ( throwStmt->expr ) {
+		const ast::StructDecl * exceptionDecl =
+			symtab.lookupStruct( "__cfaehm_base_exception_t" );
+		assert( exceptionDecl );
+		ast::ptr< ast::Type > exceptType =
+			new ast::PointerType{ new ast::StructInstType{ exceptionDecl } };
+		throwStmt = ast::mutate_field(
+			throwStmt, &ast::ThrowStmt::expr,
+			findSingleExpression( throwStmt->expr, exceptType, context ) );
+	}
+	return throwStmt;
+}
+
+const ast::CatchClause * Resolver::previsit( const ast::CatchClause * catchClause ) {
+	// Until we are very sure this invarent (ifs that move between passes have then)
+	// holds, check it. This allows a check for when to decode the mangling.
+	if ( auto ifStmt = catchClause->body.as<ast::IfStmt>() ) {
+		assert( ifStmt->then );
+	}
+	// Encode the catchStmt so the condition can see the declaration.
+	if ( catchClause->cond ) {
+		ast::CatchClause * clause = mutate( catchClause );
+		clause->body = new ast::IfStmt( clause->location, clause->cond, nullptr, clause->body );
+		clause->cond = nullptr;
+		return clause;
+	}
+	return catchClause;
+}
+
+const ast::CatchClause * Resolver::postvisit( const ast::CatchClause * catchClause ) {
+	// Decode the catchStmt so everything is stored properly.
+	const ast::IfStmt * ifStmt = catchClause->body.as<ast::IfStmt>();
+	if ( nullptr != ifStmt && nullptr == ifStmt->then ) {
+		assert( ifStmt->cond );
+		assert( ifStmt->else_ );
+		ast::CatchClause * clause = ast::mutate( catchClause );
+		clause->cond = ifStmt->cond;
+		clause->body = ifStmt->else_;
+		// ifStmt should be implicately deleted here.
+		return clause;
+	}
+	return catchClause;
+}
+
+const ast::WaitForStmt * Resolver::previsit( const ast::WaitForStmt * stmt ) {
+	visit_children = false;
+
+	// Resolve all clauses first
+	for ( unsigned i = 0; i < stmt->clauses.size(); ++i ) {
+		const ast::WaitForClause & clause = *stmt->clauses[i];
+
+		ast::TypeEnvironment env;
+		CandidateFinder funcFinder( context, env );
+
+		// Find all candidates for a function in canonical form
+		funcFinder.find( clause.target, ResolveMode::withAdjustment() );
+
+		if ( funcFinder.candidates.empty() ) {
+			stringstream ss;
+			ss << "Use of undeclared indentifier '";
+			ss << clause.target.strict_as< ast::NameExpr >()->name;
+			ss << "' in call to waitfor";
+			SemanticError( stmt->location, ss.str() );
+		}
+
+		if ( clause.target_args.empty() ) {
+			SemanticError( stmt->location,
+				"Waitfor clause must have at least one mutex parameter");
+		}
+
+		// Find all alternatives for all arguments in canonical form
+		std::vector< CandidateFinder > argFinders =
+			funcFinder.findSubExprs( clause.target_args );
+
+		// List all combinations of arguments
+		std::vector< CandidateList > possibilities;
+		combos( argFinders.begin(), argFinders.end(), back_inserter( possibilities ) );
+
+		// For every possible function:
+		// * try matching the arguments to the parameters, not the other way around because
+		//   more arguments than parameters
+		CandidateList funcCandidates;
+		std::vector< CandidateList > argsCandidates;
+		SemanticErrorException errors;
+		for ( CandidateRef & func : funcFinder.candidates ) {
+			try {
+				auto pointerType = dynamic_cast< const ast::PointerType * >(
+					func->expr->result->stripReferences() );
+				if ( ! pointerType ) {
+					SemanticError( stmt->location, func->expr->result.get(),
+						"candidate not viable: not a pointer type\n" );
+				}
+
+				auto funcType = pointerType->base.as< ast::FunctionType >();
+				if ( ! funcType ) {
+					SemanticError( stmt->location, func->expr->result.get(),
+						"candidate not viable: not a function type\n" );
+				}
+
+				{
+					auto param    = funcType->params.begin();
+					auto paramEnd = funcType->params.end();
+
+					if( ! nextMutex( param, paramEnd ) ) {
+						SemanticError( stmt->location, funcType,
+							"candidate function not viable: no mutex parameters\n");
+					}
+				}
+
+				CandidateRef func2{ new Candidate{ *func } };
+				// strip reference from function
+				func2->expr = referenceToRvalueConversion( func->expr, func2->cost );
+
+				// Each argument must be matched with a parameter of the current candidate
+				for ( auto & argsList : possibilities ) {
+					try {
+						// Declare data structures needed for resolution
+						ast::OpenVarSet open;
+						ast::AssertionSet need, have;
+						ast::TypeEnvironment resultEnv{ func->env };
+						// Add all type variables as open so that those not used in the
+						// parameter list are still considered open
+						resultEnv.add( funcType->forall );
+
+						// load type variables from arguments into one shared space
+						for ( auto & arg : argsList ) {
+							resultEnv.simpleCombine( arg->env );
+						}
+
+						// Make sure we don't widen any existing bindings
+						resultEnv.forbidWidening();
+
+						// Find any unbound type variables
+						resultEnv.extractOpenVars( open );
+
+						auto param = funcType->params.begin();
+						auto paramEnd = funcType->params.end();
+
+						unsigned n_mutex_param = 0;
+
+						// For every argument of its set, check if it matches one of the
+						// parameters. The order is important
+						for ( auto & arg : argsList ) {
+							// Ignore non-mutex arguments
+							if ( ! nextMutex( param, paramEnd ) ) {
+								// We ran out of parameters but still have arguments.
+								// This function doesn't match
+								SemanticError( stmt->location, funcType,
+									toString("candidate function not viable: too many mutex "
+									"arguments, expected ", n_mutex_param, "\n" ) );
+							}
+
+							++n_mutex_param;
+
+							// Check if the argument matches the parameter type in the current scope.
+							// ast::ptr< ast::Type > paramType = (*param)->get_type();
+
+							if (
+								! unify(
+									arg->expr->result, *param, resultEnv, need, have, open )
+							) {
+								// Type doesn't match
+								stringstream ss;
+								ss << "candidate function not viable: no known conversion "
+									"from '";
+								ast::print( ss, *param );
+								ss << "' to '";
+								ast::print( ss, arg->expr->result );
+								ss << "' with env '";
+								ast::print( ss, resultEnv );
+								ss << "'\n";
+								SemanticError( stmt->location, funcType, ss.str() );
+							}
+
+							++param;
+						}
+
+						// All arguments match!
+
+						// Check if parameters are missing
+						if ( nextMutex( param, paramEnd ) ) {
+							do {
+								++n_mutex_param;
+								++param;
+							} while ( nextMutex( param, paramEnd ) );
+
+							// We ran out of arguments but still have parameters left; this
+							// function doesn't match
+							SemanticError( stmt->location, funcType,
+								toString( "candidate function not viable: too few mutex "
+								"arguments, expected ", n_mutex_param, "\n" ) );
+						}
+
+						// All parameters match!
+
+						// Finish the expressions to tie in proper environments
+						finishExpr( func2->expr, resultEnv );
+						for ( CandidateRef & arg : argsList ) {
+							finishExpr( arg->expr, resultEnv );
+						}
+
+						// This is a match, store it and save it for later
+						funcCandidates.emplace_back( std::move( func2 ) );
+						argsCandidates.emplace_back( std::move( argsList ) );
+
+					} catch ( SemanticErrorException & e ) {
+						errors.append( e );
+					}
+				}
+			} catch ( SemanticErrorException & e ) {
+				errors.append( e );
+			}
+		}
+
+		// Make sure correct number of arguments
+		if( funcCandidates.empty() ) {
+			SemanticErrorException top( stmt->location,
+				"No alternatives for function in call to waitfor" );
+			top.append( errors );
+			throw top;
+		}
+
+		if( argsCandidates.empty() ) {
+			SemanticErrorException top( stmt->location,
+				"No alternatives for arguments in call to waitfor" );
+			top.append( errors );
+			throw top;
+		}
+
+		if( funcCandidates.size() > 1 ) {
+			SemanticErrorException top( stmt->location,
+				"Ambiguous function in call to waitfor" );
+			top.append( errors );
+			throw top;
+		}
+		if( argsCandidates.size() > 1 ) {
+			SemanticErrorException top( stmt->location,
+				"Ambiguous arguments in call to waitfor" );
+			top.append( errors );
+			throw top;
+		}
+		// TODO: need to use findDeletedExpr to ensure no deleted identifiers are used.
+
+		// build new clause
+		auto clause2 = new ast::WaitForClause( clause.location );
+
+		clause2->target = funcCandidates.front()->expr;
+
+		clause2->target_args.reserve( clause.target_args.size() );
+		const ast::StructDecl * decl_monitor = symtab.lookupStruct( "monitor$" );
+		for ( auto arg : argsCandidates.front() ) {
+			const auto & loc = stmt->location;
+
+			ast::Expr * init = new ast::CastExpr( loc,
+				new ast::UntypedExpr( loc,
+					new ast::NameExpr( loc, "get_monitor" ),
+					{ arg->expr }
+				),
+				new ast::PointerType(
+					new ast::StructInstType(
+						decl_monitor
+					)
+				)
+			);
+
+			clause2->target_args.emplace_back( findSingleExpression( init, context ) );
+		}
+
+		// Resolve the conditions as if it were an IfStmt, statements normally
+		clause2->when_cond = findSingleExpression( clause.when_cond, context );
+		clause2->stmt = clause.stmt->accept( *visitor );
+
+		// set results into stmt
+		auto n = mutate( stmt );
+		n->clauses[i] = clause2;
+		stmt = n;
+	}
+
+	if ( stmt->timeout_stmt ) {
+		// resolve the timeout as a size_t, the conditions like IfStmt, and stmts normally
+		ast::ptr< ast::Type > target =
+			new ast::BasicType{ ast::BasicType::LongLongUnsignedInt };
+		auto timeout_time = findSingleExpression( stmt->timeout_time, target, context );
+		auto timeout_cond = findSingleExpression( stmt->timeout_cond, context );
+		auto timeout_stmt = stmt->timeout_stmt->accept( *visitor );
+
+		// set results into stmt
+		auto n = mutate( stmt );
+		n->timeout_time = std::move( timeout_time );
+		n->timeout_cond = std::move( timeout_cond );
+		n->timeout_stmt = std::move( timeout_stmt );
+		stmt = n;
+	}
+
+	if ( stmt->else_stmt ) {
+		// resolve the condition like IfStmt, stmts normally
+		auto else_cond = findSingleExpression( stmt->else_cond, context );
+		auto else_stmt = stmt->else_stmt->accept( *visitor );
+
+		// set results into stmt
+		auto n = mutate( stmt );
+		n->else_cond = std::move( else_cond );
+		n->else_stmt = std::move( else_stmt );
+		stmt = n;
+	}
+
+	return stmt;
+}
+
+const ast::WithStmt * Resolver::previsit( const ast::WithStmt * withStmt ) {
+	auto mutStmt = mutate(withStmt);
+	resolveWithExprs(mutStmt->exprs, stmtsToAddBefore);
+	return mutStmt;
+}
+
+void Resolver::resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd) {
+	for (auto & expr : exprs) {
+		// only struct- and union-typed expressions are viable candidates
+		expr = findKindExpression( expr, context, structOrUnion, "with expression" );
+
+		// if with expression might be impure, create a temporary so that it is evaluated once
+		if ( Tuples::maybeImpure( expr ) ) {
+			static UniqueName tmpNamer( "_with_tmp_" );
+			const CodeLocation loc = expr->location;
+			auto tmp = new ast::ObjectDecl(loc, tmpNamer.newName(), expr->result, new ast::SingleInit(loc, expr ) );
+			expr = new ast::VariableExpr( loc, tmp );
+			stmtsToAdd.push_back( new ast::DeclStmt(loc, tmp ) );
+			if ( InitTweak::isConstructable( tmp->type ) ) {
+				// generate ctor/dtor and resolve them
+				tmp->init = InitTweak::genCtorInit( loc, tmp );
+			}
+			// since tmp is freshly created, this should modify tmp in-place
+			tmp->accept( *visitor );
+		} else if (expr->env && expr->env->empty()) {
+			expr = ast::mutate_field(expr.get(), &ast::Expr::env, nullptr);
+		}
+	}
+}
+
+const ast::SingleInit * Resolver::previsit( const ast::SingleInit * singleInit ) {
+	visit_children = false;
+	// resolve initialization using the possibilities as determined by the `currentObject`
+	// cursor.
+	ast::ptr< ast::Expr > untyped = new ast::UntypedInitExpr{
+		singleInit->location, singleInit->value, currentObject.getOptions() };
+	ast::ptr<ast::Expr> newExpr = findSingleExpression( untyped, context );
+	const ast::InitExpr * initExpr = newExpr.strict_as< ast::InitExpr >();
+
+	// move cursor to the object that is actually initialized
+	currentObject.setNext( initExpr->designation );
+
+	// discard InitExpr wrapper and retain relevant pieces.
+	// `initExpr` may have inferred params in the case where the expression specialized a
+	// function pointer, and newExpr may already have inferParams of its own, so a simple
+	// swap is not sufficient
+	ast::Expr::InferUnion inferred = initExpr->inferred;
+	swap_and_save_env( newExpr, initExpr->expr );
+	newExpr.get_and_mutate()->inferred.splice( std::move(inferred) );
+
+	// get the actual object's type (may not exactly match what comes back from the resolver
+	// due to conversions)
+	const ast::Type * initContext = currentObject.getCurrentType();
+
+	removeExtraneousCast( newExpr );
+
+	// check if actual object's type is char[]
+	if ( auto at = dynamic_cast< const ast::ArrayType * >( initContext ) ) {
+		if ( isCharType( at->base ) ) {
+			// check if the resolved type is char*
+			if ( auto pt = newExpr->result.as< ast::PointerType >() ) {
+				if ( isCharType( pt->base ) ) {
+					// strip cast if we're initializing a char[] with a char*
+					// e.g. char x[] = "hello"
+					if ( auto ce = newExpr.as< ast::CastExpr >() ) {
+						swap_and_save_env( newExpr, ce->arg );
 					}
 				}
 			}
-		};
-
-		struct ResolveDesignators final : public ast::WithShortCircuiting {
-			ResolveContext& context;
-			bool result = false;
-
-			ResolveDesignators( ResolveContext& _context ): context{_context} {};
-
-			void previsit( const ast::Node * ) {
-				// short circuit if we already know there are designations
-				if ( result ) visit_children = false;
-			}
-
-			void previsit( const ast::Designation * des ) {
-				if ( result ) visit_children = false;
-				else if ( ! des->designators.empty() ) {
-					if ( (des->designators.size() == 1) ) {
-						const ast::Expr * designator = des->designators.at(0);
-						if ( const ast::NameExpr * designatorName = dynamic_cast<const ast::NameExpr *>(designator) ) {
-							auto candidates = context.symtab.lookupId(designatorName->name);
-							for ( auto candidate : candidates ) {
-								if ( dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type()) ) {
-									result = true;
-									break;
-								}
-							}
-						}
-					}
-					visit_children = false;
-				}
-			}
-		};
-	} // anonymous namespace
-	/// Check if this expression is or includes a deleted expression
-	const ast::DeletedExpr * findDeletedExpr( const ast::Expr * expr ) {
-		return ast::Pass<DeleteFinder>::read( expr );
-	}
-
-	namespace {
-		/// always-accept candidate filter
-		bool anyCandidate( const Candidate & ) { return true; }
-
-		/// Calls the CandidateFinder and finds the single best candidate
-		CandidateRef findUnfinishedKindExpression(
-			const ast::Expr * untyped, const ResolveContext & context, const std::string & kind,
-			std::function<bool(const Candidate &)> pred = anyCandidate, ResolveMode mode = {}
-		) {
-			if ( ! untyped ) return nullptr;
-
-			// xxx - this isn't thread-safe, but should work until we parallelize the resolver
-			static unsigned recursion_level = 0;
-
-			++recursion_level;
-			ast::TypeEnvironment env;
-			CandidateFinder finder( context, env );
-			finder.allowVoid = true;
-			finder.find( untyped, recursion_level == 1 ? mode.atTopLevel() : mode );
-			--recursion_level;
-
-			// produce a filtered list of candidates
-			CandidateList candidates;
-			for ( auto & cand : finder.candidates ) {
-				if ( pred( *cand ) ) { candidates.emplace_back( cand ); }
-			}
-
-			// produce invalid error if no candidates
-			if ( candidates.empty() ) {
-				SemanticError( untyped,
-					toString( "No reasonable alternatives for ", kind, (kind != "" ? " " : ""),
-					"expression: ") );
-			}
-
-			// search for cheapest candidate
-			CandidateList winners;
-			bool seen_undeleted = false;
-			for ( CandidateRef & cand : candidates ) {
-				int c = winners.empty() ? -1 : cand->cost.compare( winners.front()->cost );
-
-				if ( c > 0 ) continue;  // skip more expensive than winner
-
-				if ( c < 0 ) {
-					// reset on new cheapest
-					seen_undeleted = ! findDeletedExpr( cand->expr );
-					winners.clear();
-				} else /* if ( c == 0 ) */ {
-					if ( findDeletedExpr( cand->expr ) ) {
-						// skip deleted expression if already seen one equivalent-cost not
-						if ( seen_undeleted ) continue;
-					} else if ( ! seen_undeleted ) {
-						// replace list of equivalent-cost deleted expressions with one non-deleted
-						winners.clear();
-						seen_undeleted = true;
-					}
-				}
-
-				winners.emplace_back( std::move( cand ) );
-			}
-
-			// promote candidate.cvtCost to .cost
-			// promoteCvtCost( winners );
-
-			// produce ambiguous errors, if applicable
-			if ( winners.size() != 1 ) {
-				std::ostringstream stream;
-				stream << "Cannot choose between " << winners.size() << " alternatives for "
-					<< kind << (kind != "" ? " " : "") << "expression\n";
-				ast::print( stream, untyped );
-				stream << " Alternatives are:\n";
-				print( stream, winners, 1 );
-				SemanticError( untyped->location, stream.str() );
-			}
-
-			// single selected choice
-			CandidateRef & choice = winners.front();
-
-			// fail on only expression deleted
-			if ( ! seen_undeleted ) {
-				SemanticError( untyped->location, choice->expr.get(), "Unique best alternative "
-				"includes deleted identifier in " );
-			}
-
-			return std::move( choice );
-		}
-
-		/// Strips extraneous casts out of an expression
-		struct StripCasts final {
-			const ast::Expr * postvisit( const ast::CastExpr * castExpr ) {
-				if (
-					castExpr->isGenerated == ast::GeneratedCast
-					&& typesCompatible( castExpr->arg->result, castExpr->result )
-				) {
-					// generated cast is the same type as its argument, remove it after keeping env
-					return ast::mutate_field(
-						castExpr->arg.get(), &ast::Expr::env, castExpr->env );
-				}
-				return castExpr;
-			}
-
-			static void strip( ast::ptr< ast::Expr > & expr ) {
-				ast::Pass< StripCasts > stripper;
-				expr = expr->accept( stripper );
-			}
-		};
-
-		/// Swaps argument into expression pointer, saving original environment
-		void swap_and_save_env( ast::ptr< ast::Expr > & expr, const ast::Expr * newExpr ) {
-			ast::ptr< ast::TypeSubstitution > env = expr->env;
-			expr.set_and_mutate( newExpr )->env = env;
-		}
-
-		/// Removes cast to type of argument (unlike StripCasts, also handles non-generated casts)
-		void removeExtraneousCast( ast::ptr<ast::Expr> & expr ) {
-			if ( const ast::CastExpr * castExpr = expr.as< ast::CastExpr >() ) {
-				if ( typesCompatible( castExpr->arg->result, castExpr->result ) ) {
-					// cast is to the same type as its argument, remove it
-					swap_and_save_env( expr, castExpr->arg );
-				}
-			}
-		}
-
-
-	} // anonymous namespace
-/// Establish post-resolver invariants for expressions
-		void finishExpr(
-			ast::ptr< ast::Expr > & expr, const ast::TypeEnvironment & env,
-			const ast::TypeSubstitution * oldenv = nullptr
-		) {
-			// set up new type substitution for expression
-			ast::ptr< ast::TypeSubstitution > newenv =
-				 oldenv ? oldenv : new ast::TypeSubstitution{};
-			env.writeToSubstitution( *newenv.get_and_mutate() );
-			expr.get_and_mutate()->env = std::move( newenv );
-			// remove unncecessary casts
-			StripCasts::strip( expr );
-		}
-
-	ast::ptr< ast::Expr > resolveInVoidContext(
-		const ast::Expr * expr, const ResolveContext & context,
-		ast::TypeEnvironment & env
-	) {
-		assertf( expr, "expected a non-null expression" );
-
-		// set up and resolve expression cast to void
-		ast::ptr< ast::CastExpr > untyped = new ast::CastExpr{ expr };
-		CandidateRef choice = findUnfinishedKindExpression(
-			untyped, context, "", anyCandidate, ResolveMode::withAdjustment() );
-
-		// a cast expression has either 0 or 1 interpretations (by language rules);
-		// if 0, an exception has already been thrown, and this code will not run
-		const ast::CastExpr * castExpr = choice->expr.strict_as< ast::CastExpr >();
-		env = std::move( choice->env );
-
-		return castExpr->arg;
-	}
-
-	/// Resolve `untyped` to the expression whose candidate is the best match for a `void`
-		/// context.
-		ast::ptr< ast::Expr > findVoidExpression(
-			const ast::Expr * untyped, const ResolveContext & context
-		) {
-			ast::TypeEnvironment env;
-			ast::ptr< ast::Expr > newExpr = resolveInVoidContext( untyped, context, env );
-			finishExpr( newExpr, env, untyped->env );
-			return newExpr;
-		}
-
-	namespace {
-
-
-		/// resolve `untyped` to the expression whose candidate satisfies `pred` with the
-		/// lowest cost, returning the resolved version
-		ast::ptr< ast::Expr > findKindExpression(
-			const ast::Expr * untyped, const ResolveContext & context,
-			std::function<bool(const Candidate &)> pred = anyCandidate,
-			const std::string & kind = "", ResolveMode mode = {}
-		) {
-			if ( ! untyped ) return {};
-			CandidateRef choice =
-				findUnfinishedKindExpression( untyped, context, kind, pred, mode );
-			ResolvExpr::finishExpr( choice->expr, choice->env, untyped->env );
-			return std::move( choice->expr );
-		}
-
-		/// Resolve `untyped` to the single expression whose candidate is the best match
-		ast::ptr< ast::Expr > findSingleExpression(
-			const ast::Expr * untyped, const ResolveContext & context
-		) {
-			Stats::ResolveTime::start( untyped );
-			auto res = findKindExpression( untyped, context );
-			Stats::ResolveTime::stop();
-			return res;
-		}
-	} // anonymous namespace
-
-	ast::ptr< ast::Expr > findSingleExpression(
-		const ast::Expr * untyped, const ast::Type * type,
-		const ResolveContext & context
-	) {
-		assert( untyped && type );
-		ast::ptr< ast::Expr > castExpr = new ast::CastExpr{ untyped, type };
-		ast::ptr< ast::Expr > newExpr = findSingleExpression( castExpr, context );
-		removeExtraneousCast( newExpr );
-		return newExpr;
-	}
-
-	namespace {
-		bool structOrUnion( const Candidate & i ) {
-			const ast::Type * t = i.expr->result->stripReferences();
-			return dynamic_cast< const ast::StructInstType * >( t ) || dynamic_cast< const ast::UnionInstType * >( t );
-		}
-		/// Predicate for "Candidate has integral type"
-		bool hasIntegralType( const Candidate & i ) {
-			const ast::Type * type = i.expr->result;
-
-			if ( auto bt = dynamic_cast< const ast::BasicType * >( type ) ) {
-				return bt->isInteger();
-			} else if (
-				dynamic_cast< const ast::EnumInstType * >( type )
-				|| dynamic_cast< const ast::ZeroType * >( type )
-				|| dynamic_cast< const ast::OneType * >( type )
-			) {
-				return true;
-			} else return false;
-		}
-
-		/// Resolve `untyped` as an integral expression, returning the resolved version
-		ast::ptr< ast::Expr > findIntegralExpression(
-			const ast::Expr * untyped, const ResolveContext & context
-		) {
-			return findKindExpression( untyped, context, hasIntegralType, "condition" );
-		}
-
-		/// check if a type is a character type
-		bool isCharType( const ast::Type * t ) {
-			if ( auto bt = dynamic_cast< const ast::BasicType * >( t ) ) {
-				return bt->kind == ast::BasicType::Char
-					|| bt->kind == ast::BasicType::SignedChar
-					|| bt->kind == ast::BasicType::UnsignedChar;
-			}
+		}
+	}
+
+	// move cursor to next object in preparation for next initializer
+	currentObject.increment();
+
+	// set initializer expression to resolved expression
+	return ast::mutate_field( singleInit, &ast::SingleInit::value, std::move(newExpr) );
+}
+
+const ast::ListInit * Resolver::previsit( const ast::ListInit * listInit ) {
+	// move cursor into brace-enclosed initializer-list
+	currentObject.enterListInit( listInit->location );
+
+	assert( listInit->designations.size() == listInit->initializers.size() );
+	for ( unsigned i = 0; i < listInit->designations.size(); ++i ) {
+		// iterate designations and initializers in pairs, moving the cursor to the current
+		// designated object and resolving the initializer against that object
+		listInit = ast::mutate_field_index(
+			listInit, &ast::ListInit::designations, i,
+			currentObject.findNext( listInit->designations[i] ) );
+		listInit = ast::mutate_field_index(
+			listInit, &ast::ListInit::initializers, i,
+			listInit->initializers[i]->accept( *visitor ) );
+	}
+
+	// move cursor out of brace-enclosed initializer-list
+	currentObject.exitListInit();
+
+	visit_children = false;
+	return listInit;
+}
+
+const ast::ConstructorInit * Resolver::previsit( const ast::ConstructorInit * ctorInit ) {
+	visitor->maybe_accept( ctorInit, &ast::ConstructorInit::ctor );
+	visitor->maybe_accept( ctorInit, &ast::ConstructorInit::dtor );
+
+	// found a constructor - can get rid of C-style initializer
+	// xxx - Rob suggests this field is dead code
+	ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::init, nullptr );
+
+	// intrinsic single-parameter constructors and destructors do nothing. Since this was
+	// implicitly generated, there's no way for it to have side effects, so get rid of it to
+	// clean up generated code
+	if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) {
+		ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::ctor, nullptr );
+	}
+	if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) {
+		ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::dtor, nullptr );
+	}
+
+	return ctorInit;
+}
+
+// suppress error on autogen functions and mark invalid autogen as deleted.
+bool Resolver::on_error(ast::ptr<ast::Decl> & decl) {
+	if (auto functionDecl = decl.as<ast::FunctionDecl>()) {
+		// xxx - can intrinsic gen ever fail?
+		if (functionDecl->linkage == ast::Linkage::AutoGen) {
+			auto mutDecl = mutate(functionDecl);
+			mutDecl->isDeleted = true;
+			mutDecl->stmts = nullptr;
+			decl = mutDecl;
 			return false;
 		}
-
-		/// Advance a type itertor to the next mutex parameter
-		template<typename Iter>
-		inline bool nextMutex( Iter & it, const Iter & end ) {
-			while ( it != end && ! (*it)->is_mutex() ) { ++it; }
-			return it != end;
-		}
-	}
-
-	class Resolver final
-	: public ast::WithSymbolTable, public ast::WithGuards,
-	  public ast::WithVisitorRef<Resolver>, public ast::WithShortCircuiting,
-	  public ast::WithStmtsToAdd<> {
-
-		ast::ptr< ast::Type > functionReturn = nullptr;
-		ast::CurrentObject currentObject;
-		// for work previously in GenInit
-		static InitTweak::ManagedTypes managedTypes;
-		ResolveContext context;
-
-		bool inEnumDecl = false;
-
-	public:
-		static size_t traceId;
-		Resolver( const ast::TranslationGlobal & global ) :
-			ast::WithSymbolTable(ast::SymbolTable::ErrorDetection::ValidateOnAdd),
-			context{ symtab, global } {}
-		Resolver( const ResolveContext & context ) :
-			ast::WithSymbolTable{ context.symtab },
-			context{ symtab, context.global } {}
-
-		const ast::FunctionDecl * previsit( const ast::FunctionDecl * );
-		const ast::FunctionDecl * postvisit( const ast::FunctionDecl * );
-		const ast::ObjectDecl * previsit( const ast::ObjectDecl * );
-		void previsit( const ast::AggregateDecl * );
-		void previsit( const ast::StructDecl * );
-		void previsit( const ast::EnumDecl * );
-		const ast::StaticAssertDecl * previsit( const ast::StaticAssertDecl * );
-
-		const ast::ArrayType * previsit( const ast::ArrayType * );
-		const ast::PointerType * previsit( const ast::PointerType * );
-
-		const ast::ExprStmt *        previsit( const ast::ExprStmt * );
-		const ast::AsmExpr *         previsit( const ast::AsmExpr * );
-		const ast::AsmStmt *         previsit( const ast::AsmStmt * );
-		const ast::IfStmt *          previsit( const ast::IfStmt * );
-		const ast::WhileDoStmt *     previsit( const ast::WhileDoStmt * );
-		const ast::ForStmt *         previsit( const ast::ForStmt * );
-		const ast::SwitchStmt *      previsit( const ast::SwitchStmt * );
-		const ast::CaseClause *      previsit( const ast::CaseClause * );
-		const ast::BranchStmt *      previsit( const ast::BranchStmt * );
-		const ast::ReturnStmt *      previsit( const ast::ReturnStmt * );
-		const ast::ThrowStmt *       previsit( const ast::ThrowStmt * );
-		const ast::CatchClause *     previsit( const ast::CatchClause * );
-		const ast::CatchClause *     postvisit( const ast::CatchClause * );
-		const ast::WaitForStmt *     previsit( const ast::WaitForStmt * );
-		const ast::WithStmt *        previsit( const ast::WithStmt * );
-
-		const ast::SingleInit *      previsit( const ast::SingleInit * );
-		const ast::ListInit *        previsit( const ast::ListInit * );
-		const ast::ConstructorInit * previsit( const ast::ConstructorInit * );
-
-		void resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd);
-
-		void beginScope() { managedTypes.beginScope(); }
-		void endScope() { managedTypes.endScope(); }
-		bool on_error(ast::ptr<ast::Decl> & decl);
-	};
-	// size_t Resolver::traceId = Stats::Heap::new_stacktrace_id("Resolver");
-
-	InitTweak::ManagedTypes Resolver::managedTypes;
-
-	void resolve( ast::TranslationUnit& translationUnit ) {
-		ast::Pass< Resolver >::run( translationUnit, translationUnit.global );
-	}
-
-	ast::ptr< ast::Init > resolveCtorInit(
-		const ast::ConstructorInit * ctorInit, const ResolveContext & context
-	) {
-		assert( ctorInit );
-		ast::Pass< Resolver > resolver( context );
-		return ctorInit->accept( resolver );
-	}
-
-	const ast::Expr * resolveStmtExpr(
-		const ast::StmtExpr * stmtExpr, const ResolveContext & context
-	) {
-		assert( stmtExpr );
-		ast::Pass< Resolver > resolver( context );
-		auto ret = mutate(stmtExpr->accept(resolver));
-		strict_dynamic_cast< ast::StmtExpr * >( ret )->computeResult();
-		return ret;
-	}
-
-	namespace {
-		const ast::Attribute * handleAttribute(const CodeLocation & loc, const ast::Attribute * attr, const ResolveContext & context) {
-			std::string name = attr->normalizedName();
-			if (name == "constructor" || name == "destructor") {
-				if (attr->params.size() == 1) {
-					auto arg = attr->params.front();
-					auto resolved = ResolvExpr::findSingleExpression( arg, new ast::BasicType( ast::BasicType::LongLongSignedInt ), context );
-					auto result = eval(arg);
-
-					auto mutAttr = mutate(attr);
-					mutAttr->params.front() = resolved;
-					if (! result.hasKnownValue) {
-						SemanticWarning(loc, Warning::GccAttributes,
-							toCString( name, " priorities must be integers from 0 to 65535 inclusive: ", arg ) );
-					}
-					else {
-						auto priority = result.knownValue;
-						if (priority < 101) {
-							SemanticWarning(loc, Warning::GccAttributes,
-								toCString( name, " priorities from 0 to 100 are reserved for the implementation" ) );
-						} else if (priority < 201 && ! buildingLibrary()) {
-							SemanticWarning(loc, Warning::GccAttributes,
-								toCString( name, " priorities from 101 to 200 are reserved for the implementation" ) );
-						}
-					}
-					return mutAttr;
-				} else if (attr->params.size() > 1) {
-					SemanticWarning(loc, Warning::GccAttributes, toCString( "too many arguments to ", name, " attribute" ) );
-				} else {
-					SemanticWarning(loc, Warning::GccAttributes, toCString( "too few arguments to ", name, " attribute" ) );
-				}
-			}
-			return attr;
-		}
-	}
-
-	const ast::FunctionDecl * Resolver::previsit( const ast::FunctionDecl * functionDecl ) {
-		GuardValue( functionReturn );
-
-		assert (functionDecl->unique());
-		if (!functionDecl->has_body() && !functionDecl->withExprs.empty()) {
-			SemanticError(functionDecl->location, functionDecl, "Function without body has with declarations");
-		}
-
-		if (!functionDecl->isTypeFixed) {
-			auto mutDecl = mutate(functionDecl);
-			auto mutType = mutDecl->type.get_and_mutate();
-
-			for (auto & attr: mutDecl->attributes) {
-				attr = handleAttribute(mutDecl->location, attr, context );
-			}
-
-			// handle assertions
-
-			symtab.enterScope();
-			mutType->forall.clear();
-			mutType->assertions.clear();
-			for (auto & typeParam : mutDecl->type_params) {
-				symtab.addType(typeParam);
-				mutType->forall.emplace_back(new ast::TypeInstType(typeParam));
-			}
-			for (auto & asst : mutDecl->assertions) {
-				asst = fixObjectType(asst.strict_as<ast::ObjectDecl>(), context);
-				symtab.addId(asst);
-				mutType->assertions.emplace_back(new ast::VariableExpr(functionDecl->location, asst));
-			}
-
-			// temporarily adds params to symbol table.
-			// actual scoping rules for params and withexprs differ - see Pass::visit(FunctionDecl)
-
-			std::vector<ast::ptr<ast::Type>> paramTypes;
-			std::vector<ast::ptr<ast::Type>> returnTypes;
-
-			for (auto & param : mutDecl->params) {
-				param = fixObjectType(param.strict_as<ast::ObjectDecl>(), context);
-				symtab.addId(param);
-				paramTypes.emplace_back(param->get_type());
-			}
-			for (auto & ret : mutDecl->returns) {
-				ret = fixObjectType(ret.strict_as<ast::ObjectDecl>(), context);
-				returnTypes.emplace_back(ret->get_type());
-			}
-			// since function type in decl is just a view of param types, need to update that as well
-			mutType->params = std::move(paramTypes);
-			mutType->returns = std::move(returnTypes);
-
-			auto renamedType = strict_dynamic_cast<const ast::FunctionType *>(renameTyVars(mutType, RenameMode::GEN_EXPR_ID));
-
-			std::list<ast::ptr<ast::Stmt>> newStmts;
-			resolveWithExprs (mutDecl->withExprs, newStmts);
-
-			if (mutDecl->stmts) {
-				auto mutStmt = mutDecl->stmts.get_and_mutate();
-				mutStmt->kids.splice(mutStmt->kids.begin(), std::move(newStmts));
-				mutDecl->stmts = mutStmt;
-			}
-
-			symtab.leaveScope();
-
-			mutDecl->type = renamedType;
-			mutDecl->mangleName = Mangle::mangle(mutDecl);
-			mutDecl->isTypeFixed = true;
-			functionDecl = mutDecl;
-		}
-		managedTypes.handleDWT(functionDecl);
-
-		functionReturn = extractResultType( functionDecl->type );
-		return functionDecl;
-	}
-
-	const ast::FunctionDecl * Resolver::postvisit( const ast::FunctionDecl * functionDecl ) {
-		// default value expressions have an environment which shouldn't be there and trips up
-		// later passes.
-		assert( functionDecl->unique() );
-		ast::FunctionType * mutType = mutate( functionDecl->type.get() );
-
-		for ( unsigned i = 0 ; i < mutType->params.size() ; ++i ) {
-			if ( const ast::ObjectDecl * obj = mutType->params[i].as< ast::ObjectDecl >() ) {
-				if ( const ast::SingleInit * init = obj->init.as< ast::SingleInit >() ) {
-					if ( init->value->env == nullptr ) continue;
-					// clone initializer minus the initializer environment
-					auto mutParam = mutate( mutType->params[i].strict_as< ast::ObjectDecl >() );
-					auto mutInit = mutate( mutParam->init.strict_as< ast::SingleInit >() );
-					auto mutValue = mutate( mutInit->value.get() );
-
-					mutValue->env = nullptr;
-					mutInit->value = mutValue;
-					mutParam->init = mutInit;
-					mutType->params[i] = mutParam;
-
-					assert( ! mutType->params[i].strict_as< ast::ObjectDecl >()->init.strict_as< ast::SingleInit >()->value->env);
-				}
-			}
-		}
-		mutate_field(functionDecl, &ast::FunctionDecl::type, mutType);
-		return functionDecl;
-	}
-
-	const ast::ObjectDecl * Resolver::previsit( const ast::ObjectDecl * objectDecl ) {
-		// To handle initialization of routine pointers [e.g. int (*fp)(int) = foo()],
-		// class-variable `initContext` is changed multiple times because the LHS is analyzed
-		// twice. The second analysis changes `initContext` because a function type can contain
-		// object declarations in the return and parameter types. Therefore each value of
-		// `initContext` is retained so the type on the first analysis is preserved and used for
-		// selecting the RHS.
-		GuardValue( currentObject );
-
-		if ( inEnumDecl && dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() ) ) {
-			// enumerator initializers should not use the enum type to initialize, since the
-			// enum type is still incomplete at this point. Use `int` instead.
-
-			if ( auto enumBase = dynamic_cast< const ast::EnumInstType * >
-				( objectDecl->get_type() )->base->base ) {
-				objectDecl = fixObjectType( objectDecl, context );
-				currentObject = ast::CurrentObject{
-					objectDecl->location,
-					enumBase
-				};
-			} else {
-				objectDecl = fixObjectType( objectDecl, context );
-				currentObject = ast::CurrentObject{
-					objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
-			}
-
-		}
-		else {
-			if ( !objectDecl->isTypeFixed ) {
-				auto newDecl = fixObjectType(objectDecl, context);
-				auto mutDecl = mutate(newDecl);
-
-				// generate CtorInit wrapper when necessary.
-				// in certain cases, fixObjectType is called before reaching
-				// this object in visitor pass, thus disabling CtorInit codegen.
-				// this happens on aggregate members and function parameters.
-				if ( InitTweak::tryConstruct( mutDecl ) && ( managedTypes.isManaged( mutDecl ) || ((! isInFunction() || mutDecl->storage.is_static ) && ! InitTweak::isConstExpr( mutDecl->init ) ) ) ) {
-					// constructed objects cannot be designated
-					if ( InitTweak::isDesignated( mutDecl->init ) ) {
-						ast::Pass<ResolveDesignators> res( context );
-						maybe_accept( mutDecl->init.get(), res );
-						if ( !res.core.result ) {
-							SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object.\n"
-										   "If this is really what you want, initialize with @=." );
-						}
-					}
-					// constructed objects should not have initializers nested too deeply
-					if ( ! InitTweak::checkInitDepth( mutDecl ) ) SemanticError( mutDecl, "Managed object's initializer is too deep " );
-
-					mutDecl->init = InitTweak::genCtorInit( mutDecl->location, mutDecl );
-				}
-
-				objectDecl = mutDecl;
-			}
-			currentObject = ast::CurrentObject{ objectDecl->location, objectDecl->get_type() };
-		}
-
-		return objectDecl;
-	}
-
-	void Resolver::previsit( const ast::AggregateDecl * _aggDecl ) {
-		auto aggDecl = mutate(_aggDecl);
-		assertf(aggDecl == _aggDecl, "type declarations must be unique");
-
-		for (auto & member: aggDecl->members) {
-			// nested type decls are hoisted already. no need to do anything
-			if (auto obj = member.as<ast::ObjectDecl>()) {
-				member = fixObjectType(obj, context);
-			}
-		}
-	}
-
-	void Resolver::previsit( const ast::StructDecl * structDecl ) {
-		previsit(static_cast<const ast::AggregateDecl *>(structDecl));
-		managedTypes.handleStruct(structDecl);
-	}
-
-	void Resolver::previsit( const ast::EnumDecl * ) {
-		// in case we decide to allow nested enums
-		GuardValue( inEnumDecl );
-		inEnumDecl = true;
-		// don't need to fix types for enum fields
-	}
-
-	const ast::StaticAssertDecl * Resolver::previsit(
-		const ast::StaticAssertDecl * assertDecl
-	) {
-		return ast::mutate_field(
-			assertDecl, &ast::StaticAssertDecl::cond,
-			findIntegralExpression( assertDecl->cond, context ) );
-	}
-
-	template< typename PtrType >
-	const PtrType * handlePtrType( const PtrType * type, const ResolveContext & context ) {
-		if ( type->dimension ) {
-			const ast::Type * sizeType = context.global.sizeType.get();
-			ast::ptr< ast::Expr > dimension = findSingleExpression( type->dimension, sizeType, context );
-			assertf(dimension->env->empty(), "array dimension expr has nonempty env");
-			dimension.get_and_mutate()->env = nullptr;
-			ast::mutate_field( type, &PtrType::dimension, dimension );
-		}
-		return type;
-	}
-
-	const ast::ArrayType * Resolver::previsit( const ast::ArrayType * at ) {
-		return handlePtrType( at, context );
-	}
-
-	const ast::PointerType * Resolver::previsit( const ast::PointerType * pt ) {
-		return handlePtrType( pt, context );
-	}
-
-	const ast::ExprStmt * Resolver::previsit( const ast::ExprStmt * exprStmt ) {
-		visit_children = false;
-		assertf( exprStmt->expr, "ExprStmt has null expression in resolver" );
-
-		return ast::mutate_field(
-			exprStmt, &ast::ExprStmt::expr, findVoidExpression( exprStmt->expr, context ) );
-	}
-
-	const ast::AsmExpr * Resolver::previsit( const ast::AsmExpr * asmExpr ) {
-		visit_children = false;
-
-		asmExpr = ast::mutate_field(
-			asmExpr, &ast::AsmExpr::operand, findVoidExpression( asmExpr->operand, context ) );
-
-		return asmExpr;
-	}
-
-	const ast::AsmStmt * Resolver::previsit( const ast::AsmStmt * asmStmt ) {
-		visitor->maybe_accept( asmStmt, &ast::AsmStmt::input );
-		visitor->maybe_accept( asmStmt, &ast::AsmStmt::output );
-		visit_children = false;
-		return asmStmt;
-	}
-
-	const ast::IfStmt * Resolver::previsit( const ast::IfStmt * ifStmt ) {
-		return ast::mutate_field(
-			ifStmt, &ast::IfStmt::cond, findIntegralExpression( ifStmt->cond, context ) );
-	}
-
-	const ast::WhileDoStmt * Resolver::previsit( const ast::WhileDoStmt * whileDoStmt ) {
-		return ast::mutate_field(
-			whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, context ) );
-	}
-
-	const ast::ForStmt * Resolver::previsit( const ast::ForStmt * forStmt ) {
-		if ( forStmt->cond ) {
-			forStmt = ast::mutate_field(
-				forStmt, &ast::ForStmt::cond, findIntegralExpression( forStmt->cond, context ) );
-		}
-
-		if ( forStmt->inc ) {
-			forStmt = ast::mutate_field(
-				forStmt, &ast::ForStmt::inc, findVoidExpression( forStmt->inc, context ) );
-		}
-
-		return forStmt;
-	}
-
-	const ast::SwitchStmt * Resolver::previsit( const ast::SwitchStmt * switchStmt ) {
-		GuardValue( currentObject );
-		switchStmt = ast::mutate_field(
-			switchStmt, &ast::SwitchStmt::cond,
-			findIntegralExpression( switchStmt->cond, context ) );
-		currentObject = ast::CurrentObject{ switchStmt->location, switchStmt->cond->result };
-		return switchStmt;
-	}
-
-	const ast::CaseClause * Resolver::previsit( const ast::CaseClause * caseStmt ) {
-		if ( caseStmt->cond ) {
-			std::deque< ast::InitAlternative > initAlts = currentObject.getOptions();
-			assertf( initAlts.size() == 1, "SwitchStmt did not correctly resolve an integral "
-				"expression." );
-
-			ast::ptr< ast::Expr > untyped =
-				new ast::CastExpr{ caseStmt->location, caseStmt->cond, initAlts.front().type };
-			ast::ptr< ast::Expr > newExpr = findSingleExpression( untyped, context );
-
-			// case condition cannot have a cast in C, so it must be removed here, regardless of
-			// whether it would perform a conversion.
-			if ( const ast::CastExpr * castExpr = newExpr.as< ast::CastExpr >() ) {
-				swap_and_save_env( newExpr, castExpr->arg );
-			}
-
-			caseStmt = ast::mutate_field( caseStmt, &ast::CaseClause::cond, newExpr );
-		}
-		return caseStmt;
-	}
-
-	const ast::BranchStmt * Resolver::previsit( const ast::BranchStmt * branchStmt ) {
-		visit_children = false;
-		// must resolve the argument of a computed goto
-		if ( branchStmt->kind == ast::BranchStmt::Goto && branchStmt->computedTarget ) {
-			// computed goto argument is void*
-			ast::ptr< ast::Type > target = new ast::PointerType{ new ast::VoidType{} };
-			branchStmt = ast::mutate_field(
-				branchStmt, &ast::BranchStmt::computedTarget,
-				findSingleExpression( branchStmt->computedTarget, target, context ) );
-		}
-		return branchStmt;
-	}
-
-	const ast::ReturnStmt * Resolver::previsit( const ast::ReturnStmt * returnStmt ) {
-		visit_children = false;
-		if ( returnStmt->expr ) {
-			returnStmt = ast::mutate_field(
-				returnStmt, &ast::ReturnStmt::expr,
-				findSingleExpression( returnStmt->expr, functionReturn, context ) );
-		}
-		return returnStmt;
-	}
-
-	const ast::ThrowStmt * Resolver::previsit( const ast::ThrowStmt * throwStmt ) {
-		visit_children = false;
-		if ( throwStmt->expr ) {
-			const ast::StructDecl * exceptionDecl =
-				symtab.lookupStruct( "__cfaehm_base_exception_t" );
-			assert( exceptionDecl );
-			ast::ptr< ast::Type > exceptType =
-				new ast::PointerType{ new ast::StructInstType{ exceptionDecl } };
-			throwStmt = ast::mutate_field(
-				throwStmt, &ast::ThrowStmt::expr,
-				findSingleExpression( throwStmt->expr, exceptType, context ) );
-		}
-		return throwStmt;
-	}
-
-	const ast::CatchClause * Resolver::previsit( const ast::CatchClause * catchClause ) {
-		// Until we are very sure this invarent (ifs that move between passes have then)
-		// holds, check it. This allows a check for when to decode the mangling.
-		if ( auto ifStmt = catchClause->body.as<ast::IfStmt>() ) {
-			assert( ifStmt->then );
-		}
-		// Encode the catchStmt so the condition can see the declaration.
-		if ( catchClause->cond ) {
-			ast::CatchClause * clause = mutate( catchClause );
-			clause->body = new ast::IfStmt( clause->location, clause->cond, nullptr, clause->body );
-			clause->cond = nullptr;
-			return clause;
-		}
-		return catchClause;
-	}
-
-	const ast::CatchClause * Resolver::postvisit( const ast::CatchClause * catchClause ) {
-		// Decode the catchStmt so everything is stored properly.
-		const ast::IfStmt * ifStmt = catchClause->body.as<ast::IfStmt>();
-		if ( nullptr != ifStmt && nullptr == ifStmt->then ) {
-			assert( ifStmt->cond );
-			assert( ifStmt->else_ );
-			ast::CatchClause * clause = ast::mutate( catchClause );
-			clause->cond = ifStmt->cond;
-			clause->body = ifStmt->else_;
-			// ifStmt should be implicately deleted here.
-			return clause;
-		}
-		return catchClause;
-	}
-
-	const ast::WaitForStmt * Resolver::previsit( const ast::WaitForStmt * stmt ) {
-		visit_children = false;
-
-		// Resolve all clauses first
-		for ( unsigned i = 0; i < stmt->clauses.size(); ++i ) {
-			const ast::WaitForClause & clause = *stmt->clauses[i];
-
-			ast::TypeEnvironment env;
-			CandidateFinder funcFinder( context, env );
-
-			// Find all candidates for a function in canonical form
-			funcFinder.find( clause.target, ResolveMode::withAdjustment() );
-
-			if ( funcFinder.candidates.empty() ) {
-				stringstream ss;
-				ss << "Use of undeclared indentifier '";
-				ss << clause.target.strict_as< ast::NameExpr >()->name;
-				ss << "' in call to waitfor";
-				SemanticError( stmt->location, ss.str() );
-			}
-
-			if ( clause.target_args.empty() ) {
-				SemanticError( stmt->location,
-					"Waitfor clause must have at least one mutex parameter");
-			}
-
-			// Find all alternatives for all arguments in canonical form
-			std::vector< CandidateFinder > argFinders =
-				funcFinder.findSubExprs( clause.target_args );
-
-			// List all combinations of arguments
-			std::vector< CandidateList > possibilities;
-			combos( argFinders.begin(), argFinders.end(), back_inserter( possibilities ) );
-
-			// For every possible function:
-			// * try matching the arguments to the parameters, not the other way around because
-			//   more arguments than parameters
-			CandidateList funcCandidates;
-			std::vector< CandidateList > argsCandidates;
-			SemanticErrorException errors;
-			for ( CandidateRef & func : funcFinder.candidates ) {
-				try {
-					auto pointerType = dynamic_cast< const ast::PointerType * >(
-						func->expr->result->stripReferences() );
-					if ( ! pointerType ) {
-						SemanticError( stmt->location, func->expr->result.get(),
-							"candidate not viable: not a pointer type\n" );
-					}
-
-					auto funcType = pointerType->base.as< ast::FunctionType >();
-					if ( ! funcType ) {
-						SemanticError( stmt->location, func->expr->result.get(),
-							"candidate not viable: not a function type\n" );
-					}
-
-					{
-						auto param    = funcType->params.begin();
-						auto paramEnd = funcType->params.end();
-
-						if( ! nextMutex( param, paramEnd ) ) {
-							SemanticError( stmt->location, funcType,
-								"candidate function not viable: no mutex parameters\n");
-						}
-					}
-
-					CandidateRef func2{ new Candidate{ *func } };
-					// strip reference from function
-					func2->expr = referenceToRvalueConversion( func->expr, func2->cost );
-
-					// Each argument must be matched with a parameter of the current candidate
-					for ( auto & argsList : possibilities ) {
-						try {
-							// Declare data structures needed for resolution
-							ast::OpenVarSet open;
-							ast::AssertionSet need, have;
-							ast::TypeEnvironment resultEnv{ func->env };
-							// Add all type variables as open so that those not used in the
-							// parameter list are still considered open
-							resultEnv.add( funcType->forall );
-
-							// load type variables from arguments into one shared space
-							for ( auto & arg : argsList ) {
-								resultEnv.simpleCombine( arg->env );
-							}
-
-							// Make sure we don't widen any existing bindings
-							resultEnv.forbidWidening();
-
-							// Find any unbound type variables
-							resultEnv.extractOpenVars( open );
-
-							auto param = funcType->params.begin();
-							auto paramEnd = funcType->params.end();
-
-							unsigned n_mutex_param = 0;
-
-							// For every argument of its set, check if it matches one of the
-							// parameters. The order is important
-							for ( auto & arg : argsList ) {
-								// Ignore non-mutex arguments
-								if ( ! nextMutex( param, paramEnd ) ) {
-									// We ran out of parameters but still have arguments.
-									// This function doesn't match
-									SemanticError( stmt->location, funcType,
-										toString("candidate function not viable: too many mutex "
-										"arguments, expected ", n_mutex_param, "\n" ) );
-								}
-
-								++n_mutex_param;
-
-								// Check if the argument matches the parameter type in the current scope.
-								// ast::ptr< ast::Type > paramType = (*param)->get_type();
-
-								if (
-									! unify(
-										arg->expr->result, *param, resultEnv, need, have, open )
-								) {
-									// Type doesn't match
-									stringstream ss;
-									ss << "candidate function not viable: no known conversion "
-										"from '";
-									ast::print( ss, *param );
-									ss << "' to '";
-									ast::print( ss, arg->expr->result );
-									ss << "' with env '";
-									ast::print( ss, resultEnv );
-									ss << "'\n";
-									SemanticError( stmt->location, funcType, ss.str() );
-								}
-
-								++param;
-							}
-
-							// All arguments match!
-
-							// Check if parameters are missing
-							if ( nextMutex( param, paramEnd ) ) {
-								do {
-									++n_mutex_param;
-									++param;
-								} while ( nextMutex( param, paramEnd ) );
-
-								// We ran out of arguments but still have parameters left; this
-								// function doesn't match
-								SemanticError( stmt->location, funcType,
-									toString( "candidate function not viable: too few mutex "
-									"arguments, expected ", n_mutex_param, "\n" ) );
-							}
-
-							// All parameters match!
-
-							// Finish the expressions to tie in proper environments
-							finishExpr( func2->expr, resultEnv );
-							for ( CandidateRef & arg : argsList ) {
-								finishExpr( arg->expr, resultEnv );
-							}
-
-							// This is a match, store it and save it for later
-							funcCandidates.emplace_back( std::move( func2 ) );
-							argsCandidates.emplace_back( std::move( argsList ) );
-
-						} catch ( SemanticErrorException & e ) {
-							errors.append( e );
-						}
-					}
-				} catch ( SemanticErrorException & e ) {
-					errors.append( e );
-				}
-			}
-
-			// Make sure correct number of arguments
-			if( funcCandidates.empty() ) {
-				SemanticErrorException top( stmt->location,
-					"No alternatives for function in call to waitfor" );
-				top.append( errors );
-				throw top;
-			}
-
-			if( argsCandidates.empty() ) {
-				SemanticErrorException top( stmt->location,
-					"No alternatives for arguments in call to waitfor" );
-				top.append( errors );
-				throw top;
-			}
-
-			if( funcCandidates.size() > 1 ) {
-				SemanticErrorException top( stmt->location,
-					"Ambiguous function in call to waitfor" );
-				top.append( errors );
-				throw top;
-			}
-			if( argsCandidates.size() > 1 ) {
-				SemanticErrorException top( stmt->location,
-					"Ambiguous arguments in call to waitfor" );
-				top.append( errors );
-				throw top;
-			}
-			// TODO: need to use findDeletedExpr to ensure no deleted identifiers are used.
-
-			// build new clause
-			auto clause2 = new ast::WaitForClause( clause.location );
-
-			clause2->target = funcCandidates.front()->expr;
-
-			clause2->target_args.reserve( clause.target_args.size() );
-			const ast::StructDecl * decl_monitor = symtab.lookupStruct( "monitor$" );
-			for ( auto arg : argsCandidates.front() ) {
-				const auto & loc = stmt->location;
-
-				ast::Expr * init = new ast::CastExpr( loc,
-					new ast::UntypedExpr( loc,
-						new ast::NameExpr( loc, "get_monitor" ),
-						{ arg->expr }
-					),
-					new ast::PointerType(
-						new ast::StructInstType(
-							decl_monitor
-						)
-					)
-				);
-
-				clause2->target_args.emplace_back( findSingleExpression( init, context ) );
-			}
-
-			// Resolve the conditions as if it were an IfStmt, statements normally
-			clause2->when_cond = findSingleExpression( clause.when_cond, context );
-			clause2->stmt = clause.stmt->accept( *visitor );
-
-			// set results into stmt
-			auto n = mutate( stmt );
-			n->clauses[i] = clause2;
-			stmt = n;
-		}
-
-		if ( stmt->timeout_stmt ) {
-			// resolve the timeout as a size_t, the conditions like IfStmt, and stmts normally
-			ast::ptr< ast::Type > target =
-				new ast::BasicType{ ast::BasicType::LongLongUnsignedInt };
-			auto timeout_time = findSingleExpression( stmt->timeout_time, target, context );
-			auto timeout_cond = findSingleExpression( stmt->timeout_cond, context );
-			auto timeout_stmt = stmt->timeout_stmt->accept( *visitor );
-
-			// set results into stmt
-			auto n = mutate( stmt );
-			n->timeout_time = std::move( timeout_time );
-			n->timeout_cond = std::move( timeout_cond );
-			n->timeout_stmt = std::move( timeout_stmt );
-			stmt = n;
-		}
-
-		if ( stmt->else_stmt ) {
-			// resolve the condition like IfStmt, stmts normally
-			auto else_cond = findSingleExpression( stmt->else_cond, context );
-			auto else_stmt = stmt->else_stmt->accept( *visitor );
-
-			// set results into stmt
-			auto n = mutate( stmt );
-			n->else_cond = std::move( else_cond );
-			n->else_stmt = std::move( else_stmt );
-			stmt = n;
-		}
-
-		return stmt;
-	}
-
-	const ast::WithStmt * Resolver::previsit( const ast::WithStmt * withStmt ) {
-		auto mutStmt = mutate(withStmt);
-		resolveWithExprs(mutStmt->exprs, stmtsToAddBefore);
-		return mutStmt;
-	}
-
-	void Resolver::resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd) {
-		for (auto & expr : exprs) {
-			// only struct- and union-typed expressions are viable candidates
-			expr = findKindExpression( expr, context, structOrUnion, "with expression" );
-
-			// if with expression might be impure, create a temporary so that it is evaluated once
-			if ( Tuples::maybeImpure( expr ) ) {
-				static UniqueName tmpNamer( "_with_tmp_" );
-				const CodeLocation loc = expr->location;
-				auto tmp = new ast::ObjectDecl(loc, tmpNamer.newName(), expr->result, new ast::SingleInit(loc, expr ) );
-				expr = new ast::VariableExpr( loc, tmp );
-				stmtsToAdd.push_back( new ast::DeclStmt(loc, tmp ) );
-				if ( InitTweak::isConstructable( tmp->type ) ) {
-					// generate ctor/dtor and resolve them
-					tmp->init = InitTweak::genCtorInit( loc, tmp );
-				}
-				// since tmp is freshly created, this should modify tmp in-place
-				tmp->accept( *visitor );
-			}
-			else if (expr->env && expr->env->empty()) {
-				expr = ast::mutate_field(expr.get(), &ast::Expr::env, nullptr);
-			}
-		}
-	}
-
-
-	const ast::SingleInit * Resolver::previsit( const ast::SingleInit * singleInit ) {
-		visit_children = false;
-		// resolve initialization using the possibilities as determined by the `currentObject`
-		// cursor.
-		ast::ptr< ast::Expr > untyped = new ast::UntypedInitExpr{
-			singleInit->location, singleInit->value, currentObject.getOptions() };
-		ast::ptr<ast::Expr> newExpr = findSingleExpression( untyped, context );
-		const ast::InitExpr * initExpr = newExpr.strict_as< ast::InitExpr >();
-
-		// move cursor to the object that is actually initialized
-		currentObject.setNext( initExpr->designation );
-
-		// discard InitExpr wrapper and retain relevant pieces.
-		// `initExpr` may have inferred params in the case where the expression specialized a
-		// function pointer, and newExpr may already have inferParams of its own, so a simple
-		// swap is not sufficient
-		ast::Expr::InferUnion inferred = initExpr->inferred;
-		swap_and_save_env( newExpr, initExpr->expr );
-		newExpr.get_and_mutate()->inferred.splice( std::move(inferred) );
-
-		// get the actual object's type (may not exactly match what comes back from the resolver
-		// due to conversions)
-		const ast::Type * initContext = currentObject.getCurrentType();
-
-		removeExtraneousCast( newExpr );
-
-		// check if actual object's type is char[]
-		if ( auto at = dynamic_cast< const ast::ArrayType * >( initContext ) ) {
-			if ( isCharType( at->base ) ) {
-				// check if the resolved type is char*
-				if ( auto pt = newExpr->result.as< ast::PointerType >() ) {
-					if ( isCharType( pt->base ) ) {
-						// strip cast if we're initializing a char[] with a char*
-						// e.g. char x[] = "hello"
-						if ( auto ce = newExpr.as< ast::CastExpr >() ) {
-							swap_and_save_env( newExpr, ce->arg );
-						}
-					}
-				}
-			}
-		}
-
-		// move cursor to next object in preparation for next initializer
-		currentObject.increment();
-
-		// set initializer expression to resolved expression
-		return ast::mutate_field( singleInit, &ast::SingleInit::value, std::move(newExpr) );
-	}
-
-	const ast::ListInit * Resolver::previsit( const ast::ListInit * listInit ) {
-		// move cursor into brace-enclosed initializer-list
-		currentObject.enterListInit( listInit->location );
-
-		assert( listInit->designations.size() == listInit->initializers.size() );
-		for ( unsigned i = 0; i < listInit->designations.size(); ++i ) {
-			// iterate designations and initializers in pairs, moving the cursor to the current
-			// designated object and resolving the initializer against that object
-			listInit = ast::mutate_field_index(
-				listInit, &ast::ListInit::designations, i,
-				currentObject.findNext( listInit->designations[i] ) );
-			listInit = ast::mutate_field_index(
-				listInit, &ast::ListInit::initializers, i,
-				listInit->initializers[i]->accept( *visitor ) );
-		}
-
-		// move cursor out of brace-enclosed initializer-list
-		currentObject.exitListInit();
-
-		visit_children = false;
-		return listInit;
-	}
-
-	const ast::ConstructorInit * Resolver::previsit( const ast::ConstructorInit * ctorInit ) {
-		visitor->maybe_accept( ctorInit, &ast::ConstructorInit::ctor );
-		visitor->maybe_accept( ctorInit, &ast::ConstructorInit::dtor );
-
-		// found a constructor - can get rid of C-style initializer
-		// xxx - Rob suggests this field is dead code
-		ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::init, nullptr );
-
-		// intrinsic single-parameter constructors and destructors do nothing. Since this was
-		// implicitly generated, there's no way for it to have side effects, so get rid of it to
-		// clean up generated code
-		if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) {
-			ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::ctor, nullptr );
-		}
-		if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) {
-			ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::dtor, nullptr );
-		}
-
-		return ctorInit;
-	}
-
-	// suppress error on autogen functions and mark invalid autogen as deleted.
-	bool Resolver::on_error(ast::ptr<ast::Decl> & decl) {
-		if (auto functionDecl = decl.as<ast::FunctionDecl>()) {
-			// xxx - can intrinsic gen ever fail?
-			if (functionDecl->linkage == ast::Linkage::AutoGen) {
-				auto mutDecl = mutate(functionDecl);
-				mutDecl->isDeleted = true;
-				mutDecl->stmts = nullptr;
-				decl = mutDecl;
-				return false;
-			}
-		}
-		return true;
-	}
+	}
+	return true;
+}
 
 } // namespace ResolvExpr
Index: src/SymTab/GenImplicitCall.cpp
===================================================================
--- src/SymTab/GenImplicitCall.cpp	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/SymTab/GenImplicitCall.cpp	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// GenImplicitCall.hpp --
+// GenImplicitCall.cpp -- Generate code for implicit operator calls.
 //
 // Author           : Andrew Beach
@@ -31,8 +31,9 @@
 namespace {
 
-template< typename OutIter >
+using Inserter = std::back_insert_iterator<std::list<ast::ptr<ast::Stmt>>>;
+
 ast::ptr< ast::Stmt > genCall(
 	InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
-	const CodeLocation & loc, const std::string & fname, OutIter && out,
+	const CodeLocation & loc, const std::string & fname, Inserter && out,
 	const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward );
 
@@ -41,8 +42,7 @@
 /// optionally returns a statement which must be inserted prior to the containing loop, if
 /// there is one
-template< typename OutIter >
 ast::ptr< ast::Stmt > genScalarCall(
 	InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
-	const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type,
+	const CodeLocation & loc, std::string fname, Inserter && out, const ast::Type * type,
 	const ast::Type * addCast = nullptr
 ) {
@@ -97,8 +97,7 @@
 /// Store in out a loop which calls fname on each element of the array with srcParam and
 /// dstParam as arguments. If forward is true, loop goes from 0 to N-1, else N-1 to 0
-template< typename OutIter >
 void genArrayCall(
 	InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
-	const CodeLocation & loc, const std::string & fname, OutIter && out,
+	const CodeLocation & loc, const std::string & fname, Inserter && out,
 	const ast::ArrayType * array, const ast::Type * addCast = nullptr,
 	LoopDirection forward = LoopForward
@@ -166,18 +165,17 @@
 }
 
-template< typename OutIter >
 ast::ptr< ast::Stmt > genCall(
 	InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
-	const CodeLocation & loc, const std::string & fname, OutIter && out,
+	const CodeLocation & loc, const std::string & fname, Inserter && out,
 	const ast::Type * type, const ast::Type * addCast, LoopDirection forward
 ) {
 	if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) {
 		genArrayCall(
-			srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast,
+			srcParam, dstParam, loc, fname, std::forward< Inserter&& >( out ), at, addCast,
 			forward );
 		return {};
 	} else {
 		return genScalarCall(
-			srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast );
+			srcParam, dstParam, loc, fname, std::forward< Inserter&& >( out ), type, addCast );
 	}
 }
@@ -185,5 +183,5 @@
 } // namespace
 
-ast::ptr< ast::Stmt > genImplicitCall(
+const ast::Stmt * genImplicitCall(
 	InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
 	const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj,
@@ -191,5 +189,5 @@
 ) {
 	// unnamed bit fields are not copied as they cannot be accessed
-	if ( isUnnamedBitfield( obj ) ) return {};
+	if ( isUnnamedBitfield( obj ) ) return nullptr;
 
 	ast::ptr< ast::Type > addCast;
@@ -199,22 +197,18 @@
 	}
 
-	std::vector< ast::ptr< ast::Stmt > > stmts;
+	std::list< ast::ptr< ast::Stmt > > stmts;
 	genCall(
 		srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward );
 
-	if ( stmts.empty() ) {
-		return {};
-	} else if ( stmts.size() == 1 ) {
-		const ast::Stmt * callStmt = stmts.front();
-		if ( addCast ) {
-			// implicitly generated ctor/dtor calls should be wrapped so that later passes are
-			// aware they were generated.
-			callStmt = new ast::ImplicitCtorDtorStmt( callStmt->location, callStmt );
-		}
-		return callStmt;
-	} else {
-		assert( false );
-		return {};
-	}
+	if ( stmts.empty() ) return nullptr;
+	assert( stmts.size() == 1 );
+
+	const ast::Stmt * callStmt = stmts.front().release();
+	// Implicitly generated ctor/dtor calls should be wrapped so that
+	// later passes are aware they were generated.
+	if ( addCast ) {
+		callStmt = new ast::ImplicitCtorDtorStmt( callStmt->location, callStmt );
+	}
+	return callStmt;
 }
 
@@ -226,4 +220,2 @@
 // compile-command: "make install" //
 // End: //
-
-
Index: src/SymTab/GenImplicitCall.hpp
===================================================================
--- src/SymTab/GenImplicitCall.hpp	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/SymTab/GenImplicitCall.hpp	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// GenImplicitCall.hpp --
+// GenImplicitCall.hpp -- Generate code for implicit operator calls.
 //
 // Author           : Andrew Beach
@@ -25,5 +25,5 @@
 /// Returns a generated call expression to function fname with srcParam and
 /// dstParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
-ast::ptr<ast::Stmt> genImplicitCall(
+const ast::Stmt * genImplicitCall(
 	InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
 	const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj,
Index: src/Validate/Autogen.cpp
===================================================================
--- src/Validate/Autogen.cpp	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/Validate/Autogen.cpp	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -133,6 +133,5 @@
 	/// Generates a single struct member operation.
 	/// (constructor call, destructor call, assignment call)
-	// This is managed because it uses another helper that returns a ast::ptr.
-	ast::ptr<ast::Stmt> makeMemberOp(
+	const ast::Stmt * makeMemberOp(
 		const CodeLocation& location,
 		const ast::ObjectDecl * dstParam, const ast::Expr * src,
@@ -525,5 +524,5 @@
 }
 
-ast::ptr<ast::Stmt> StructFuncGenerator::makeMemberOp(
+const ast::Stmt * StructFuncGenerator::makeMemberOp(
 		const CodeLocation& location, const ast::ObjectDecl * dstParam,
 		const ast::Expr * src, const ast::ObjectDecl * field,
@@ -540,5 +539,5 @@
 		)
 	);
-	auto stmt = genImplicitCall(
+	const ast::Stmt * stmt = genImplicitCall(
 		srcParam, dstSelect, location, func->name,
 		field, direction
@@ -598,9 +597,9 @@
 			location, field, new ast::VariableExpr( location, srcParam )
 		) : nullptr;
-		ast::ptr<ast::Stmt> stmt =
+		const ast::Stmt * stmt =
 			makeMemberOp( location, dstParam, srcSelect, field, func, direction );
 
 		if ( nullptr != stmt ) {
-			stmts->kids.push_back( stmt );
+			stmts->kids.emplace_back( stmt );
 		}
 	}
@@ -623,5 +622,5 @@
 	for ( auto param = params.begin() + 1 ; current != end ; ++current ) {
 		const ast::ptr<ast::Decl> & member = *current;
-		ast::ptr<ast::Stmt> stmt = nullptr;
+		const ast::Stmt * stmt = nullptr;
 		auto field = member.as<ast::ObjectDecl>();
 		// Not sure why it could be null.
@@ -641,5 +640,5 @@
 
 		if ( nullptr != stmt ) {
-			stmts->kids.push_back( stmt );
+			stmts->kids.emplace_back( stmt );
 		}
 	}
Index: src/main.cc
===================================================================
--- src/main.cc	(revision 0522ebe7b3ae7204a1d2c50a1bc7273bfa36762a)
+++ src/main.cc	(revision 3f9a8d0ec2f7cd020d50f08e995ba642d316f6bb)
@@ -181,4 +181,5 @@
 
 static void _Signal(struct sigaction & act, int sig, int flags ) {
+	sigemptyset( &act.sa_mask );
 	act.sa_flags = flags;
 
