diff --git a/src/Expr.cc b/src/Expr.cc index 5cee1cce38..3382515847 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3112,7 +3112,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li SetType(make_intrusive(make_intrusive(IntrusivePtr{AdoptRef{}, base_type(TYPE_ANY)}), nullptr)); else { - SetType({AdoptRef{}, init_type(op.get())}); + SetType(init_type(op.get())); if ( ! type ) SetError(); @@ -3225,7 +3225,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, if ( op->AsListExpr()->Exprs().empty() ) SetType(make_intrusive<::SetType>(make_intrusive(IntrusivePtr{AdoptRef{}, base_type(TYPE_ANY)}), nullptr)); else - SetType({AdoptRef{}, init_type(op.get())}); + SetType(init_type(op.get())); } if ( ! type ) diff --git a/src/Type.cc b/src/Type.cc index cbebe06b68..b59a8ffc8f 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1983,7 +1983,7 @@ static BroType* reduce_type(BroType* t) return t; } -BroType* init_type(Expr* init) +IntrusivePtr init_type(Expr* init) { if ( init->Tag() != EXPR_LIST ) { @@ -1999,7 +1999,7 @@ BroType* init_type(Expr* init) return nullptr; } - return t.release(); + return t; } ListExpr* init_list = init->AsListExpr(); @@ -2017,7 +2017,7 @@ BroType* init_type(Expr* init) if ( e0->IsRecordElement(0) ) // ListExpr's know how to build a record from their // components. - return init_list->InitType().release(); + return init_list->InitType(); auto t = e0->InitType(); @@ -2049,7 +2049,7 @@ BroType* init_type(Expr* init) if ( t->Tag() == TYPE_TABLE && ! t->AsTableType()->IsSet() ) // A list of table elements. - return t.release(); + return t; // A set. If the index type isn't yet a type list, make // it one, as that's what's required for creating a set type. @@ -2060,7 +2060,7 @@ BroType* init_type(Expr* init) t = std::move(tl); } - return new SetType({AdoptRef{}, t.release()->AsTypeList()}, nullptr); + return make_intrusive(IntrusivePtr{AdoptRef{}, t.release()->AsTypeList()}, nullptr); } bool is_atomic_type(const BroType* t) diff --git a/src/Type.h b/src/Type.h index f3cdf2d289..7075d3565e 100644 --- a/src/Type.h +++ b/src/Type.h @@ -725,7 +725,7 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2); IntrusivePtr merge_type_list(ListExpr* elements); // Given an expression, infer its type when used for an initialization. -extern BroType* init_type(Expr* init); +IntrusivePtr init_type(Expr* init); // Returns true if argument is an atomic type. bool is_atomic_type(const BroType* t); diff --git a/src/Var.cc b/src/Var.cc index 6b95dea094..888f1bd788 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -64,7 +64,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, if ( id->Type() && id->Type()->Tag() != TYPE_ERROR ) { if ( dt != VAR_REDEF && - (! init || ! do_init || (! t && ! (t = {AdoptRef{}, init_type(init.get())}))) ) + (! init || ! do_init || (! t && ! (t = init_type(init.get())))) ) { id->Error("already defined", init.get()); return; @@ -103,7 +103,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, return; } - t = {AdoptRef{}, init_type(init.get())}; + t = init_type(init.get()); if ( ! t ) { id->SetType({AdoptRef{}, error_type()});