Index: src/SymTab/Validate.cc
===================================================================
--- src/SymTab/Validate.cc	(revision 5189888c01c25f70a752b7907df395785fca58cd)
+++ src/SymTab/Validate.cc	(revision f5234f377ada7d47d16f2cf07778a4ca2e416546)
@@ -625,4 +625,12 @@
 	}
 
+	/// Clones a reference type, replacing any parameters it may have with a clone of the provided list
+	template< typename GenericInstType >
+	GenericInstType *cloneWithParams( GenericInstType *refType, const std::list< Expression* >& params ) {
+		GenericInstType *clone = refType->clone();
+		clone->get_parameters().clear();
+		cloneAll( params, clone->get_parameters() );
+		return clone;
+	}
 
 	Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) {
@@ -631,15 +639,18 @@
 		// Make function polymorphic in same parameters as generic struct, if applicable
 		std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
+		std::list< Expression* > structParams;  // List of matching parameters to put on types
 		for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
-			assignType->get_forall().push_back( (*param)->clone() );
+			TypeDecl *typeParam = (*param)->clone();
+			assignType->get_forall().push_back( typeParam );
+			structParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) );
 		}
   
-		ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
+		ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );
 		assignType->get_returnVals().push_back( returnVal );
   
-		ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
+		ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, structParams ) ), 0 );
 		assignType->get_parameters().push_back( dstParam );
   
-		ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
+		ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );
 		assignType->get_parameters().push_back( srcParam );
 
@@ -677,12 +688,21 @@
 	Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) {
 		FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
-  
-		ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
+
+		// Make function polymorphic in same parameters as generic union, if applicable
+		std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
+		std::list< Expression* > unionParams;  // List of matching parameters to put on types
+		for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
+			TypeDecl *typeParam = (*param)->clone();
+			assignType->get_forall().push_back( typeParam );
+			unionParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) );
+		}
+  
+		ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 );
 		assignType->get_returnVals().push_back( returnVal );
   
-		ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
+		ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, unionParams ) ), 0 );
 		assignType->get_parameters().push_back( dstParam );
   
-		ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
+		ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 );
 		assignType->get_parameters().push_back( srcParam );
   
@@ -695,5 +715,5 @@
 		copy->get_args().push_back( new VariableExpr( dstParam ) );
 		copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
-		copy->get_args().push_back( new SizeofExpr( refType->clone() ) );
+		copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams ) ) );
 
 		assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) );
@@ -714,7 +734,7 @@
 	void AutogenerateRoutines::visit( StructDecl *structDecl ) {
 		if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
-			StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
-			structInst->set_baseStruct( structDecl );
-			declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) );
+			StructInstType structInst( Type::Qualifiers(), structDecl->get_name() );
+			structInst.set_baseStruct( structDecl );
+			declsToAdd.push_back( makeStructAssignment( structDecl, &structInst, functionNesting ) );
 			structsDone.insert( structDecl->get_name() );
 		} // if
@@ -723,7 +743,7 @@
 	void AutogenerateRoutines::visit( UnionDecl *unionDecl ) {
 		if ( ! unionDecl->get_members().empty() ) {
-			UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
-			unionInst->set_baseUnion( unionDecl );
-			declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );
+			UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() );
+			unionInst.set_baseUnion( unionDecl );
+			declsToAdd.push_back( makeUnionAssignment( unionDecl, &unionInst, functionNesting ) );
 		} // if
 	}
