Index: src/ControlStruct/TranslateEnumRange.cpp
===================================================================
--- src/ControlStruct/TranslateEnumRange.cpp	(revision 73d0e3f4e0ab67804cda0bdfa2660e3905620544)
+++ src/ControlStruct/TranslateEnumRange.cpp	(revision 6d2b3dcd9e518ea112923a8e83105ce7a4a77fd6)
@@ -22,11 +22,6 @@
         auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>();
         auto type = typeExpr->type;
-        auto inits = stmt->inits;
-        auto enumInst = type.strict_as<ast::EnumInstType>();
-        auto enumDecl = enumInst->base;
 
         auto objInit = stmt->inits.front();
-        auto initLocation = objInit->location;
-        auto rangeLocation = stmt->range_over->location;
         assert( stmt->inits.size() == 1 );
 
@@ -47,10 +42,5 @@
 const ast::Stmt* addInit::postvisit( const ast::ForStmt * stmt ) {
     if ( stmt->range_over ) {
-        auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>();
-        auto type = typeExpr->type;
         auto inits = stmt->inits;
-        auto enumInst = type.strict_as<ast::EnumInstType>();
-        auto enumDecl = enumInst->base;
-
         auto init = stmt->inits.front();
 
@@ -60,8 +50,10 @@
                 if ( !objDecl->init ) {
                     auto location = stmt->location;
-                    // auto newInit = new ast::SingleInit( location, new ast::NameExpr( location, enumDecl->members.front()->name ) );
                     ast::SingleInit * newInit = new ast::SingleInit( location, 
-                        new ast::NameExpr( location, 
-                           stmt->is_inc? enumDecl->members.front()->name: enumDecl->members.back()->name ) );
+                        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 );
@@ -80,8 +72,4 @@
     auto initDecl = declStmt->decl.strict_as<ast::ObjectDecl>();
     auto indexName = initDecl->name;
-    
-    auto typeExpr = stmt->range_over.strict_as<ast::TypeExpr>();
-    auto enumInst = typeExpr->type.strict_as<ast::EnumInstType>();
-    auto enumDecl = enumInst->base;
 
     // Both inc and dec check if the current posn less than the number of enumerator
@@ -90,13 +78,9 @@
     ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location,
         "?<=?",
-        {new ast::CastExpr(location,
-            new ast::NameExpr( location, indexName ),
-            new ast::BasicType( ast::BasicKind::UnsignedInt 
-        ),ast::GeneratedFlag::ExplicitCast),
-        ast::ConstantExpr::from_ulong( location, enumDecl->members.size()-1 ) });
+        {   new ast::NameExpr( location, indexName ),
+            ast::UntypedExpr::createCall( location, "upperBound", {} )  });
     auto increment = ast::UntypedExpr::createCall( location, 
-        stmt->is_inc? "succ": "pred",{
-        new ast::NameExpr( location, indexName )
-    });
+        stmt->is_inc? "succ": "pred",
+        { 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 );
@@ -106,5 +90,4 @@
 
 void translateEnumRange( ast::TranslationUnit & translationUnit ) {
-    ast::Pass<addInitType>::run( translationUnit );
     ast::Pass<addInit>::run( translationUnit );
     ast::Pass<translateEnumRangeCore>::run( translationUnit );
