Fix clang-tidy modernize-use-emplace findings

This commit is contained in:
Tim Wojtulewicz 2025-05-16 10:28:59 -07:00
parent 3943e64372
commit a3078f3132
9 changed files with 19 additions and 20 deletions

View file

@ -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.

View file

@ -696,8 +696,8 @@ StmtPtr ScriptFunc::AddInits(StmtPtr body, const std::vector<IDPtr>& inits) {
auto stmt_series = with_location_of(make_intrusive<StmtList>(), body);
auto init = with_location_of(make_intrusive<InitStmt>(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;
}

View file

@ -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<StringVal>(len, reinterpret_cast<const char*>(data)));
args.emplace_back(make_intrusive<StringVal>(len, reinterpret_cast<const char*>(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);

View file

@ -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();

View file

@ -775,7 +775,7 @@ void Manager::Peer(const string& addr, uint16_t port, double retry) {
auto secs = broker::timeout::seconds(static_cast<uint64_t>(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();
}

View file

@ -82,10 +82,8 @@ std::optional<broker::zeek::Event> 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<broker::count>(m.Id());
entry[1] = res.value();
broker_meta.push_back(std::move(entry));
broker::vector entry{static_cast<broker::count>(m.Id()), res.value()};
broker_meta.emplace_back(std::move(entry));
}
else {
// Just for sanity - we should never get here.

View file

@ -281,7 +281,7 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::
return;
auto ie_s = with_location_of(make_intrusive<ExprStmt>(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<CoalescedScriptFunc>(merged_body, new_scope, func);

View file

@ -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<Stmt*>(s)});
stmts.emplace_back(NewRef{}, const_cast<Stmt*>(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<Expr*>(e)});
exprs.emplace_back(NewRef{}, const_cast<Expr*>(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<Location*>(s->GetLocationInfo());
UpdateLocInfo(loc);
block_line_range.emplace_back(std::pair<int, int>{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<FuncInfo>& funcs) {
auto body_loc = body->GetLocationInfo();
fn = func_name_at_loc(fn, body_loc);
parents.emplace_back(std::pair<std::string, std::string>{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<std::string, std::string>{LocWithFunc(loc), std::move(ls)});
parents.emplace_back(LocWithFunc(loc), std::move(ls));
return TC_CONTINUE;
}

View file

@ -376,7 +376,7 @@ NameExprPtr Reducer::GenInlineBlockName(const IDPtr& id) {
void Reducer::PushInlineBlock() {
++inline_block_level;
block_locals.emplace_back(std::unordered_map<const ID*, IDPtr>());
block_locals.emplace_back();
}
void Reducer::PopInlineBlock() {