Index: src/ControlStruct/TranslateEnumRange.cpp
===================================================================
--- src/ControlStruct/TranslateEnumRange.cpp	(revision dcfcf368f79594eb9cffea05e52b6e6ca5967954)
+++ src/ControlStruct/TranslateEnumRange.cpp	(revision 8c79dc3cf042f621ce268dde92e2f27f6f0672ae)
@@ -6,67 +6,59 @@
 namespace ControlStruct {
 
-struct addInit {
-    const ast::Stmt * postvisit( const ast::ForStmt * stmt );
+namespace {
+
+struct TranslateEnumRangeCore {
+	const ast::Stmt * postvisit( const ast::ForStmt * stmt );
 };
 
-struct translateEnumRangeCore {
-    const ast::Stmt * postvisit( const ast::ForStmt * stmt );
-};
+const ast::Stmt * TranslateEnumRangeCore::postvisit( const ast::ForStmt * stmt ) {
+	if ( !stmt->range_over ) return stmt;
+	auto mutStmt = ast::mutate( stmt );
+	auto & location = mutStmt->location;
 
-const ast::Stmt* addInit::postvisit( const ast::ForStmt * stmt ) {
-    if ( stmt->range_over ) {
-        auto inits = stmt->inits;
-        auto init = stmt->inits.front();
+	if ( auto declStmt = mutStmt->inits.front().as<ast::DeclStmt>() ) {
+		if ( auto objDecl = declStmt->decl.as<ast::ObjectDecl>() ) {
+			if ( !objDecl->init ) {
+				ast::SingleInit * newInit = new ast::SingleInit( location,
+					ast::UntypedExpr::createCall( location,
+						mutStmt->is_inc ? "lowerBound" : "upperBound", {} ),
+					ast::ConstructFlag::MaybeConstruct
+				);
+				auto objDeclWithInit = ast::mutate_field( objDecl, &ast::ObjectDecl::init, newInit );
+				auto declWithInit = ast::mutate_field( declStmt, &ast::DeclStmt::decl, objDeclWithInit );
+				mutStmt->inits[0] = declWithInit;
+			}
+		}
+	}
 
-        if (auto declStmt = init.as<ast::DeclStmt>()) {
-            auto decl = declStmt->decl;
-            if ( auto objDecl = decl.as<ast::ObjectDecl>()) {
-                if ( !objDecl->init ) {
-                    auto location = stmt->location;
-                    ast::SingleInit * newInit = new ast::SingleInit( location, 
-                        stmt->is_inc?
-                        ast::UntypedExpr::createCall( location, "lowerBound", {} ):
-                        ast::UntypedExpr::createCall( location, "upperBound", {} ),
-                        ast::ConstructFlag::MaybeConstruct
-                    );
-                    auto objDeclWithInit = ast::mutate_field( objDecl, &ast::ObjectDecl::init, newInit );
-                    auto declWithInit = ast::mutate_field( declStmt, &ast::DeclStmt::decl, objDeclWithInit );
-                    stmt = ast::mutate_field_index( stmt, &ast::ForStmt::inits, 0, declWithInit );
-                }
-            }
-        }
-    }
-    return stmt;
+	auto declStmt = mutStmt->inits.front().strict_as<ast::DeclStmt>();
+	auto initDecl = declStmt->decl.strict_as<ast::ObjectDecl>();
+	auto indexName = initDecl->name;
+
+	// Both inc and dec check if the current posn less than the number of enumerator
+	// for dec, it keeps call pred until it passes 0 (the first enumerator) and underflow,
+	// it wraps around and become unsigned max
+	ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location,
+		mutStmt->is_inc ? "?<=?" : "?>=?",
+		{
+			new ast::NameExpr( location, indexName ),
+			ast::UntypedExpr::createCall( location,
+				mutStmt->is_inc ? "upperBound" : "lowerBound", {} )
+		} );
+	auto increment = ast::UntypedExpr::createCall( location,
+		mutStmt->is_inc ? "succ_unsafe" : "pred_unsafe",
+		{ new ast::NameExpr( location, indexName ) } );
+	auto assig = ast::UntypedExpr::createAssign( location,
+		new ast::NameExpr( location, indexName ), increment );
+	mutStmt->cond = condition;
+	mutStmt->inc = assig;
+	return mutStmt;
 }
 
-const ast::Stmt* translateEnumRangeCore::postvisit( const ast::ForStmt * stmt ) {
-    if ( !stmt->range_over ) return stmt;
-    auto location = stmt->location;
-    auto declStmt = stmt->inits.front().strict_as<ast::DeclStmt>();
-    auto initDecl = declStmt->decl.strict_as<ast::ObjectDecl>();
-    auto indexName = initDecl->name;
-
-    // Both inc and dec check if the current posn less than the number of enumerator
-    // for dec, it keeps call pred until it passes 0 (the first enumerator) and underflow,
-    // it wraps around and become unsigned max
-    ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location,
-        stmt->is_inc? "?<=?": "?>=?",
-        {   new ast::NameExpr( location, indexName ),
-            stmt->is_inc?
-                ast::UntypedExpr::createCall( location, "upperBound", {} ):
-                ast::UntypedExpr::createCall( location, "lowerBound", {} )
-        });
-    auto increment = ast::UntypedExpr::createCall( location, 
-        stmt->is_inc? "succ_unsafe": "pred_unsafe",
-        { new ast::NameExpr( location, indexName ) });
-    auto assig = ast::UntypedExpr::createAssign( location, new ast::NameExpr( location, indexName ), increment );
-    auto mut = ast::mutate_field( stmt, &ast::ForStmt::cond, condition );
-    mut = ast::mutate_field(stmt, &ast::ForStmt::inc, assig );
-    return mut;
-}  
+} // namespace
 
 void translateEnumRange( ast::TranslationUnit & translationUnit ) {
-    ast::Pass<addInit>::run( translationUnit );
-    ast::Pass<translateEnumRangeCore>::run( translationUnit );
+	ast::Pass<TranslateEnumRangeCore>::run( translationUnit );
 }
-}
+
+} // namespace ControlStruct
Index: src/Parser/TypeData.cpp
===================================================================
--- src/Parser/TypeData.cpp	(revision dcfcf368f79594eb9cffea05e52b6e6ca5967954)
+++ src/Parser/TypeData.cpp	(revision 8c79dc3cf042f621ce268dde92e2f27f6f0672ae)
@@ -1457,6 +1457,12 @@
 	assert( td->kind == TypeData::Aggregate );
 	assert( td->aggregate.kind == ast::AggregateDecl::Enum );
-	ast::ptr<ast::Type> baseType = td->base ? typebuild(td->base) : nullptr;
-
+	ast::ptr<ast::Type> baseType;
+	if ( td->base ) {
+		if ( td->base->kind == TypeData::Aggregate ) {
+			baseType = buildComAggInst( td->base, copy(attributes), linkage );
+		} else {
+			baseType = typebuild( td->base );
+		}
+	}
 	ast::EnumDecl * ret = new ast::EnumDecl(
 		td->location,
