diff --git a/src/Type.h b/src/Type.h index dcdbc09e0d..fafa79dee1 100644 --- a/src/Type.h +++ b/src/Type.h @@ -366,6 +366,15 @@ public: protected: IndexType(TypeTag t, TypeListPtr arg_indices, TypePtr arg_yield_type) : Type(t), indices(std::move(arg_indices)), yield_type(std::move(arg_yield_type)) { + // "indices" might be nil if we're deferring construction of the type + // for "-O use-C++" initialization. + if ( indices ) + SetSpecialIndices(); + else + is_subnet_index = is_pattern_index = false; // placeholders + } + + void SetSpecialIndices() { const auto& types = indices->GetTypes(); is_subnet_index = types.size() == 1 && types[0]->Tag() == TYPE_SUBNET; is_pattern_index = types.size() == 1 && types[0]->Tag() == TYPE_PATTERN; diff --git a/src/script_opt/CPP/InitsInfo.cc b/src/script_opt/CPP/InitsInfo.cc index c8150dbe96..b887eec1b4 100644 --- a/src/script_opt/CPP/InitsInfo.cc +++ b/src/script_opt/CPP/InitsInfo.cc @@ -441,7 +441,7 @@ TableTypeInfo::TableTypeInfo(CPPCompile* _c, TypePtr _t) : AbstractTypeInfo(_c, auto gi = c->RegisterType(tbl->GetIndices()); ASSERT(gi); indices = gi->Offset(); - final_init_cohort = gi->InitCohort(); + final_init_cohort = gi->InitCohort() + 1; yield = tbl->Yield(); diff --git a/src/script_opt/CPP/RuntimeInitSupport.h b/src/script_opt/CPP/RuntimeInitSupport.h index 80a25db7fb..6f400a8d98 100644 --- a/src/script_opt/CPP/RuntimeInitSupport.h +++ b/src/script_opt/CPP/RuntimeInitSupport.h @@ -22,8 +22,10 @@ public: CPPTableType() : TableType(nullptr, nullptr){}; void SetIndexAndYield(TypeListPtr ind, TypePtr yield) { - ind = std::move(indices); + indices = std::move(ind); yield_type = std::move(yield); + SetSpecialIndices(); + RegenerateHash(); } }; diff --git a/src/script_opt/CPP/RuntimeOps.cc b/src/script_opt/CPP/RuntimeOps.cc index ae2b9c7744..680f4648cc 100644 --- a/src/script_opt/CPP/RuntimeOps.cc +++ b/src/script_opt/CPP/RuntimeOps.cc @@ -221,7 +221,7 @@ TableValPtr set_constructor__CPP(vector elements, TableTypePtr t, vector auto aggr = make_intrusive(std::move(t), std::move(attrs)); for ( auto& elem : elements ) - aggr->Assign(std::move(elem), nullptr); + aggr->Assign(elem, nullptr); return aggr; }