diff --git a/.clang-tidy b/.clang-tidy index 4d9daefbad..da09d22227 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,6 +10,7 @@ Checks: [-*, modernize-return-braced-init-list, modernize-use-bool-literals, modernize-use-default-member-init, + modernize-use-emplace, # Enable a very limited number of the cppcoreguidelines checkers. # See the notes for some of the rest of them below. diff --git a/src/Func.cc b/src/Func.cc index c612f0b979..a476521b55 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -696,8 +696,8 @@ StmtPtr ScriptFunc::AddInits(StmtPtr body, const std::vector& inits) { auto stmt_series = with_location_of(make_intrusive(), body); auto init = with_location_of(make_intrusive(inits), body); - stmt_series->Stmts().push_back(std::move(init)); - stmt_series->Stmts().push_back(std::move(body)); + stmt_series->Stmts().emplace_back(std::move(init)); + stmt_series->Stmts().emplace_back(std::move(body)); return stmt_series; } diff --git a/src/RuleAction.cc b/src/RuleAction.cc index 1aabae37a1..2a11115dc1 100644 --- a/src/RuleAction.cc +++ b/src/RuleAction.cc @@ -92,15 +92,15 @@ void RuleActionEvent::DoAction(const Rule* parent, RuleEndpointState* state, con if ( handler ) { zeek::Args args; args.reserve(msg ? 3 : 2); - args.push_back({AdoptRef{}, rule_matcher->BuildRuleStateValue(parent, state)}); + args.emplace_back(AdoptRef{}, rule_matcher->BuildRuleStateValue(parent, state)); if ( msg ) - args.push_back(msg); + args.emplace_back(msg); if ( data ) - args.push_back(make_intrusive(len, reinterpret_cast(data))); + args.emplace_back(make_intrusive(len, reinterpret_cast(data))); else - args.push_back(zeek::val_mgr->EmptyString()); + args.emplace_back(zeek::val_mgr->EmptyString()); if ( want_end_of_match ) { auto* match = state->FindRulePatternMatch(parent); diff --git a/src/Val.cc b/src/Val.cc index 6c52fb875a..bff527f82c 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1638,7 +1638,7 @@ bool detail::TablePatternMatcher::MatchAll(const StringValPtr& s) { void detail::TablePatternMatcher::Build() { matcher_yields.clear(); - matcher_yields.push_back(nullptr); + matcher_yields.emplace_back(nullptr); auto& tbl_dict = *tbl->Get(); auto& tbl_hash = *tbl->GetTableHash(); diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index e182764085..06cbb431be 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -775,7 +775,7 @@ void Manager::Peer(const string& addr, uint16_t port, double retry) { auto secs = broker::timeout::seconds(static_cast(retry)); bstate->endpoint.peer_nosync(addr, port, secs); - bstate->outbound_peerings.emplace(broker::network_info(addr, port)); + bstate->outbound_peerings.emplace(addr, port); auto counts_as_iosource = get_option("Broker::peer_counts_as_iosource")->AsBool(); @@ -1160,7 +1160,7 @@ RecordVal* Manager::MakeEvent(ValPList* args, zeek::detail::Frame* frame) { zeek::Args cargs; cargs.reserve(args->size()); for ( auto* a : *args ) - cargs.push_back({zeek::NewRef{}, a}); + cargs.emplace_back(zeek::NewRef{}, a); return MakeEvent(ArgsSpan{cargs}, frame)->Ref()->AsRecordVal(); } diff --git a/src/cluster/serializer/broker/Serializer.cc b/src/cluster/serializer/broker/Serializer.cc index e0bdcde4b2..1d036caa65 100644 --- a/src/cluster/serializer/broker/Serializer.cc +++ b/src/cluster/serializer/broker/Serializer.cc @@ -82,10 +82,8 @@ std::optional detail::to_broker_event(const detail::Event& for ( const auto& m : *meta ) { if ( auto res = zeek::Broker::detail::val_to_data(m.Val().get()); res.has_value() ) { - broker::vector entry(2); - entry[0] = static_cast(m.Id()); - entry[1] = res.value(); - broker_meta.push_back(std::move(entry)); + broker::vector entry{static_cast(m.Id()), res.value()}; + broker_meta.emplace_back(std::move(entry)); } else { // Just for sanity - we should never get here. diff --git a/src/script_opt/Inline.cc b/src/script_opt/Inline.cc index 410ceec678..ebdeb2e5d3 100644 --- a/src/script_opt/Inline.cc +++ b/src/script_opt/Inline.cc @@ -281,7 +281,7 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector(ie), bp); - merged_body->Stmts().push_back(std::move(ie_s)); + merged_body->Stmts().emplace_back(std::move(ie_s)); } auto inlined_func = make_intrusive(merged_body, new_scope, func); diff --git a/src/script_opt/ProfileFunc.cc b/src/script_opt/ProfileFunc.cc index 463b29ab53..df221a223e 100644 --- a/src/script_opt/ProfileFunc.cc +++ b/src/script_opt/ProfileFunc.cc @@ -101,7 +101,7 @@ ProfileFunc::ProfileFunc(const Expr* e, bool _abs_rec_fields) { } TraversalCode ProfileFunc::PreStmt(const Stmt* s) { - stmts.push_back({NewRef{}, const_cast(s)}); + stmts.emplace_back(NewRef{}, const_cast(s)); switch ( s->Tag() ) { case STMT_INIT: @@ -185,7 +185,7 @@ TraversalCode ProfileFunc::PreStmt(const Stmt* s) { } TraversalCode ProfileFunc::PreExpr(const Expr* e) { - exprs.push_back({NewRef{}, const_cast(e)}); + exprs.emplace_back(NewRef{}, const_cast(e)); TrackType(e->GetType()); @@ -1476,7 +1476,7 @@ std::string func_name_at_loc(std::string fname, const Location* loc) { TraversalCode SetBlockLineNumbers::PreStmt(const Stmt* s) { auto loc = const_cast(s->GetLocationInfo()); UpdateLocInfo(loc); - block_line_range.emplace_back(std::pair{loc->first_line, loc->last_line}); + block_line_range.emplace_back(loc->first_line, loc->last_line); return TC_CONTINUE; } @@ -1535,7 +1535,7 @@ ASTBlockAnalyzer::ASTBlockAnalyzer(std::vector& funcs) { auto body_loc = body->GetLocationInfo(); fn = func_name_at_loc(fn, body_loc); - parents.emplace_back(std::pair{fn, fn}); + parents.emplace_back(fn, fn); func_name_prefix = fn + ":"; body->Traverse(this); parents.pop_back(); @@ -1555,7 +1555,7 @@ TraversalCode ASTBlockAnalyzer::PreStmt(const Stmt* s) { auto ls = BuildExpandedDescription(loc); if ( is_compound_stmt(s) ) - parents.push_back(std::pair{LocWithFunc(loc), std::move(ls)}); + parents.emplace_back(LocWithFunc(loc), std::move(ls)); return TC_CONTINUE; } diff --git a/src/script_opt/Reduce.cc b/src/script_opt/Reduce.cc index 5808c5f2de..44afdafd4a 100644 --- a/src/script_opt/Reduce.cc +++ b/src/script_opt/Reduce.cc @@ -376,7 +376,7 @@ NameExprPtr Reducer::GenInlineBlockName(const IDPtr& id) { void Reducer::PushInlineBlock() { ++inline_block_level; - block_locals.emplace_back(std::unordered_map()); + block_locals.emplace_back(); } void Reducer::PopInlineBlock() {