Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision f1f481a248c0e686d11a61bd4f4a6f4a950f5d31)
+++ src/GenPoly/Box.cc	(revision 0b1ca470cb4e37c87b603e45955c6cb1b5962233)
@@ -249,7 +249,7 @@
 		std::list< TypeDecl * > otypeDecls;
 
-		for ( std::list< TypeDecl* >::const_iterator decl = decls.begin(); decl != decls.end(); ++decl ) {
-			if ( (*decl)->isComplete() ) {
-				otypeDecls.push_back( *decl );
+		for ( TypeDecl * const decl : decls ) {
+			if ( decl->isComplete() ) {
+				otypeDecls.push_back( decl );
 			}
 		}
@@ -262,6 +262,6 @@
 		BasicType sizeAlignType( Type::Qualifiers(), BasicType::LongUnsignedInt );
 
-		for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) {
-			TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param );
+		for ( TypeDecl * const param : otypeParams ) {
+			TypeInstType paramType( Type::Qualifiers(), param->get_name(), param );
 			std::string paramName = mangleType( &paramType );
 			layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
@@ -411,6 +411,6 @@
 		addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
 		addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
-		for ( std::list< Declaration* >::const_iterator member = unionDecl->get_members().begin(); member != unionDecl->get_members().end(); ++member ) {
-			DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member );
+		for ( Declaration * const member : unionDecl->members ) {
+			DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( member );
 			assert( dwt );
 			Type *memberType = dwt->get_type();
@@ -440,6 +440,6 @@
 			// to take those polymorphic types as pointers. Therefore, there can be two different functions
 			// with the same mangled name, so we need to further mangle the names.
-			for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval ) {
-				if ( isPolyType( (*retval)->get_type(), tyVars ) ) {
+			for ( DeclarationWithType * const ret : function->get_returnVals() ) {
+				if ( isPolyType( ret->get_type(), tyVars ) ) {
 					name << "P";
 				} else {
@@ -448,7 +448,6 @@
 			}
 			name << "_";
-			std::list< DeclarationWithType *> &paramList = function->get_parameters();
-			for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
-				if ( isPolyType( (*arg)->get_type(), tyVars ) ) {
+			for ( DeclarationWithType * const arg : function->get_parameters() ) {
+				if ( isPolyType( arg->get_type(), tyVars ) ) {
 					name << "P";
 				} else {
@@ -492,18 +491,18 @@
 				std::list< DeclarationWithType *> &paramList = functionType->parameters;
 				std::list< FunctionType *> functions;
-				for ( Type::ForallList::iterator tyVar = functionType->forall.begin(); tyVar != functionType->forall.end(); ++tyVar ) {
-					for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->assertions.begin(); assert != (*tyVar)->assertions.end(); ++assert ) {
-						findFunction( (*assert)->get_type(), functions, scopeTyVars, needsAdapter );
+				for ( TypeDecl * const tyVar : functionType->forall ) {
+					for ( DeclarationWithType * const assert : tyVar->assertions ) {
+						findFunction( assert->get_type(), functions, scopeTyVars, needsAdapter );
 					} // for
 				} // for
-				for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
-					findFunction( (*arg)->get_type(), functions, scopeTyVars, needsAdapter );
+				for ( DeclarationWithType * const arg : paramList ) {
+					findFunction( arg->get_type(), functions, scopeTyVars, needsAdapter );
 				} // for
 
-				for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
-					std::string mangleName = mangleAdapterName( *funType, scopeTyVars );
+				for ( FunctionType * const funType : functions ) {
+					std::string mangleName = mangleAdapterName( funType, scopeTyVars );
 					if ( adapters.find( mangleName ) == adapters.end() ) {
 						std::string adapterName = makeAdapterName( mangleName );
-						adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), nullptr ) ) );
+						adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), nullptr ) ) );
 					} // if
 				} // for
@@ -562,9 +561,9 @@
 		void Pass1::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
 			// pass size/align for type variables
-			for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) {
+			for ( std::pair<std::string, TypeDecl::Data> const & tyParam : exprTyVars ) {
 				ResolvExpr::EqvClass eqvClass;
 				assert( env );
-				if ( tyParm->second.isComplete ) {
-					Type *concrete = env->lookup( tyParm->first );
+				if ( tyParam.second.isComplete ) {
+					Type *concrete = env->lookup( tyParam.first );
 					if ( concrete ) {
 						arg = appExpr->get_args().insert( arg, new SizeofExpr( concrete->clone() ) );
@@ -574,5 +573,5 @@
 					} else {
 						// xxx - should this be an assertion?
-						SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParm->first, " in application " ) );
+						SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParam.first, " in application " ) );
 					} // if
 				} // if
@@ -890,13 +889,12 @@
 		void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) {
 			// collect a list of function types passed as parameters or implicit parameters (assertions)
-			std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
-			std::list< FunctionType *> functions;
-			for ( Type::ForallList::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar ) {
-				for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->get_assertions().begin(); assert != (*tyVar)->get_assertions().end(); ++assert ) {
-					findFunction( (*assert)->get_type(), functions, exprTyVars, needsAdapter );
+			std::list< FunctionType*> functions;
+			for ( TypeDecl * const tyVar : functionType->get_forall() ) {
+				for ( DeclarationWithType * const assert : tyVar->get_assertions() ) {
+					findFunction( assert->get_type(), functions, exprTyVars, needsAdapter );
 				} // for
 			} // for
-			for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
-				findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter );
+			for ( DeclarationWithType * const arg : functionType->get_parameters() ) {
+				findFunction( arg->get_type(), functions, exprTyVars, needsAdapter );
 			} // for
 
@@ -905,7 +903,7 @@
 			std::set< std::string > adaptersDone;
 
-			for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
-				FunctionType *originalFunction = (*funType)->clone();
-				FunctionType *realFunction = (*funType)->clone();
+			for ( FunctionType * const funType : functions ) {
+				FunctionType *originalFunction = funType->clone();
+				FunctionType *realFunction = funType->clone();
 				std::string mangleName = SymTab::Mangler::mangle( realFunction );
 
@@ -925,5 +923,5 @@
 					if ( adapter == adapters.end() ) {
 						// adapter has not been created yet in the current scope, so define it
-						FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );
+						FunctionDecl *newAdapter = makeAdapter( funType, realFunction, mangleName, exprTyVars );
 						std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) );
 						adapter = answer.first;
@@ -1228,16 +1226,16 @@
 			std::list< DeclarationWithType *> &paramList = functionType->parameters;
 			std::list< FunctionType *> functions;
-			for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
-				Type *orig = (*arg)->get_type();
+			for (  DeclarationWithType * const arg : functionType->parameters ) {
+				Type *orig = arg->get_type();
 				findAndReplaceFunction( orig, functions, scopeTyVars, needsAdapter );
-				(*arg)->set_type( orig );
+				arg->set_type( orig );
 			}
 			std::set< std::string > adaptersDone;
-			for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
-				std::string mangleName = mangleAdapterName( *funType, scopeTyVars );
+			for ( FunctionType * const funType : functions ) {
+				std::string mangleName = mangleAdapterName( funType, scopeTyVars );
 				if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
 					std::string adapterName = makeAdapterName( mangleName );
 					// adapter may not be used in body, pass along with unused attribute.
-					paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) );
+					paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) );
 					adaptersDone.insert( adaptersDone.begin(), mangleName );
 				}
@@ -1316,9 +1314,9 @@
 			ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0,
 			                   new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 );
-			for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
+			for ( TypeDecl * const tyParam : funcType->get_forall() ) {
 				ObjectDecl *sizeParm, *alignParm;
 				// add all size and alignment parameters to parameter list
-				if ( (*tyParm)->isComplete() ) {
-					TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
+				if ( tyParam->isComplete() ) {
+					TypeInstType parmType( Type::Qualifiers(), tyParam->get_name(), tyParam );
 					std::string parmName = mangleType( &parmType );
 
@@ -1334,16 +1332,16 @@
 				}
 				// move all assertions into parameter list
-				for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) {
+				for ( DeclarationWithType * const assert : tyParam->get_assertions() ) {
 					// assertion parameters may not be used in body, pass along with unused attribute.
-					(*assert)->get_attributes().push_back( new Attribute( "unused" ) );
-					inferredParams.push_back( *assert );
-				}
-				(*tyParm)->get_assertions().clear();
+					assert->get_attributes().push_back( new Attribute( "unused" ) );
+					inferredParams.push_back( assert );
+				}
+				tyParam->get_assertions().clear();
 			}
 
 			// add size/align for generic parameter types to parameter list
 			std::set< std::string > seenTypes; // sizeofName for generic types we've seen
-			for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) {
-				Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars );
+			for ( DeclarationWithType * const fnParam : funcType->get_parameters() ) {
+				Type *polyType = isPolyType( fnParam->get_type(), scopeTyVars );
 				if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) {
 					std::string typeName = mangleType( polyType );
@@ -1464,7 +1462,7 @@
 
 			// make sure that any type information passed into the function is accounted for
-			for ( std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin(); fnParm != funcType->get_parameters().end(); ++fnParm ) {
+			for ( DeclarationWithType * const fnParam : funcType->get_parameters() ) {
 				// condition here duplicates that in Pass2::mutate( FunctionType* )
-				Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars );
+				Type *polyType = isPolyType( fnParam->get_type(), scopeTyVars );
 				if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) {
 					knownLayouts.insert( mangleType( polyType ) );
@@ -1539,12 +1537,13 @@
 		/// Finds the member in the base list that matches the given declaration; returns its index, or -1 if not present
 		long findMember( DeclarationWithType *memberDecl, std::list< Declaration* > &baseDecls ) {
-			long i = 0;
-			for(std::list< Declaration* >::const_iterator decl = baseDecls.begin(); decl != baseDecls.end(); ++decl, ++i ) {
-				if ( memberDecl->get_name() != (*decl)->get_name() )
+			for ( auto pair : enumerate( baseDecls ) ) {
+				Declaration * decl = pair.val;
+				size_t i = pair.idx;
+				if ( memberDecl->get_name() != decl->get_name() )
 					continue;
 
 				if ( memberDecl->get_name().empty() ) {
 					// plan-9 field: match on unique_id
-					if ( memberDecl->get_uniqueId() == (*decl)->get_uniqueId() )
+					if ( memberDecl->get_uniqueId() == decl->get_uniqueId() )
 						return i;
 					else
@@ -1552,5 +1551,5 @@
 				}
 
-				DeclarationWithType *declWithType = strict_dynamic_cast< DeclarationWithType* >( *decl );
+				DeclarationWithType *declWithType = strict_dynamic_cast< DeclarationWithType* >( decl );
 
 				if ( memberDecl->get_mangleName().empty() || declWithType->get_mangleName().empty() ) {
@@ -1663,13 +1662,13 @@
 
 		void PolyGenericCalculator::addOtypeParamsToLayoutCall( UntypedExpr *layoutCall, const std::list< Type* > &otypeParams ) {
-			for ( std::list< Type* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) {
-				if ( findGeneric( *param ) ) {
+			for ( Type * const param : otypeParams ) {
+				if ( findGeneric( param ) ) {
 					// push size/align vars for a generic parameter back
-					std::string paramName = mangleType( *param );
+					std::string paramName = mangleType( param );
 					layoutCall->get_args().push_back( new NameExpr( sizeofName( paramName ) ) );
 					layoutCall->get_args().push_back( new NameExpr( alignofName( paramName ) ) );
 				} else {
-					layoutCall->get_args().push_back( new SizeofExpr( (*param)->clone() ) );
-					layoutCall->get_args().push_back( new AlignofExpr( (*param)->clone() ) );
+					layoutCall->get_args().push_back( new SizeofExpr( param->clone() ) );
+					layoutCall->get_args().push_back( new AlignofExpr( param->clone() ) );
 				}
 			}
@@ -1932,2 +1931,3 @@
 // compile-command: "make install" //
 // End: //
+
Index: src/GenPoly/InstantiateGenericNew.cpp
===================================================================
--- src/GenPoly/InstantiateGenericNew.cpp	(revision f1f481a248c0e686d11a61bd4f4a6f4a950f5d31)
+++ src/GenPoly/InstantiateGenericNew.cpp	(revision 0b1ca470cb4e37c87b603e45955c6cb1b5962233)
@@ -476,5 +476,4 @@
 };
 
-// I think this and the UnionInstType can be made into a template function.
 ast::Type const * GenericInstantiator::postvisit(
 		ast::StructInstType const * inst ) {
