diff --git a/.clang-tidy b/.clang-tidy index 1683ac36a1..7c590c811b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,6 +7,7 @@ Checks: [-*, modernize-min-max-use-initializer-list, modernize-pass-by-value, modernize-redundant-void-arg, + modernize-return-braced-init-list, # Enable a very limited number of the cppcoreguidelines checkers. # See the notes for some of the rest of them below. diff --git a/src/PrefixTable.cc b/src/PrefixTable.cc index a30dcc1568..95fff9e09c 100644 --- a/src/PrefixTable.cc +++ b/src/PrefixTable.cc @@ -19,8 +19,8 @@ prefix_t* PrefixTable::MakePrefix(const IPAddr& addr, int width) { } IPPrefix PrefixTable::PrefixToIPPrefix(prefix_t* prefix) { - return IPPrefix(IPAddr(IPv6, reinterpret_cast(&prefix->add.sin6), IPAddr::Network), prefix->bitlen, - true); + return {IPAddr(IPv6, reinterpret_cast(&prefix->add.sin6), IPAddr::Network), + static_cast(prefix->bitlen), true}; } void* PrefixTable::Insert(const IPAddr& addr, int width, void* data) { diff --git a/src/Type.cc b/src/Type.cc index a5c6f935b5..cc0842bba9 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -902,7 +902,7 @@ public: auto v = init_expr->Eval(nullptr); if ( ! v ) { reporter->Error("failed &default in record creation"); - return ZVal(); + return {}; } if ( coerce_type ) @@ -911,7 +911,7 @@ public: else if ( init_type->Tag() == TYPE_VECTOR ) concretize_if_unspecified(cast_intrusive(v), init_type->Yield()); - return ZVal(v, init_type); + return {v, init_type}; } bool IsDeferrable() const override { return false; } @@ -930,7 +930,7 @@ class RecordFieldInit final : public FieldInit { public: RecordFieldInit(RecordTypePtr _init_type) : init_type(std::move(_init_type)) {} - ZVal Generate() const override { return ZVal(new RecordVal(init_type)); } + ZVal Generate() const override { return {new RecordVal(init_type)}; } bool IsDeferrable() const override { assert(! run_state::is_parsing); @@ -948,7 +948,7 @@ public: TableFieldInit(TableTypePtr _init_type, detail::AttributesPtr _attrs) : init_type(std::move(_init_type)), attrs(std::move(_attrs)) {} - ZVal Generate() const override { return ZVal(new TableVal(init_type, attrs)); } + ZVal Generate() const override { return {new TableVal(init_type, attrs)}; } private: TableTypePtr init_type; @@ -961,7 +961,7 @@ class VectorFieldInit final : public FieldInit { public: VectorFieldInit(VectorTypePtr _init_type) : init_type(std::move(_init_type)) {} - ZVal Generate() const override { return ZVal(new VectorVal(init_type)); } + ZVal Generate() const override { return {new VectorVal(init_type)}; } private: VectorTypePtr init_type; diff --git a/src/input/readers/raw/Plugin.cc b/src/input/readers/raw/Plugin.cc index f42f4a9ff2..6c1193fc0e 100644 --- a/src/input/readers/raw/Plugin.cc +++ b/src/input/readers/raw/Plugin.cc @@ -22,6 +22,6 @@ void Plugin::InitPreScript() {} void Plugin::Done() {} -std::unique_lock Plugin::ForkMutex() { return std::unique_lock(fork_mutex, std::defer_lock); } +std::unique_lock Plugin::ForkMutex() { return {fork_mutex, std::defer_lock}; } } // namespace zeek::plugin::detail::Zeek_RawReader diff --git a/src/probabilistic/BitVector.cc b/src/probabilistic/BitVector.cc index 8bde14a74c..f1d6208ab1 100644 --- a/src/probabilistic/BitVector.cc +++ b/src/probabilistic/BitVector.cc @@ -350,7 +350,7 @@ bool BitVector::operator[](size_type i) const { BitVector::Reference BitVector::operator[](size_type i) { assert(i < num_bits); - return Reference(bits[block_index(i)], bit_index(i)); + return {bits[block_index(i)], bit_index(i)}; } BitVector::size_type BitVector::Count() const { diff --git a/src/script_opt/CPP/Exprs.cc b/src/script_opt/CPP/Exprs.cc index e3e78caef4..d0562d7a7e 100644 --- a/src/script_opt/CPP/Exprs.cc +++ b/src/script_opt/CPP/Exprs.cc @@ -141,7 +141,7 @@ string CPPCompile::GenExpr(const Expr* e, GenType gt, bool top_level) { default: // Intended to catch errors in overlooking the possible // expressions that might appear. - return string("EXPR"); + return "EXPR"; } } @@ -825,7 +825,7 @@ string CPPCompile::GenVal(const ValPtr& v) { auto it = t->InternalType(); if ( tag == TYPE_BOOL ) - return string(v->IsZero() ? "false" : "true"); + return v->IsZero() ? "false" : "true"; if ( tag == TYPE_ENUM ) return GenEnum(t, v); diff --git a/src/script_opt/ZAM/Inst-Gen.cc b/src/script_opt/ZAM/Inst-Gen.cc index 9788995bb9..37eaa01d45 100644 --- a/src/script_opt/ZAM/Inst-Gen.cc +++ b/src/script_opt/ZAM/Inst-Gen.cc @@ -6,9 +6,9 @@ namespace zeek::detail { -ZInstI ZAMCompiler::GenInst(ZOp op) { return ZInstI(op); } +ZInstI ZAMCompiler::GenInst(ZOp op) { return {op}; } -ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1) { return ZInstI(op, Frame1Slot(v1, op)); } +ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1) { return {op, Frame1Slot(v1, op)}; } ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, int i) { auto z = ZInstI(op, Frame1Slot(v1, op), i); @@ -24,46 +24,42 @@ ZInstI ZAMCompiler::GenInst(ZOp op, const ConstExpr* c, const NameExpr* v1, int ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const NameExpr* v2) { int nv2 = FrameSlot(v2); - return ZInstI(op, Frame1Slot(v1, op), nv2); + return {op, Frame1Slot(v1, op), nv2}; } ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const NameExpr* v2, const NameExpr* v3) { int nv2 = FrameSlot(v2); int nv3 = FrameSlot(v3); - return ZInstI(op, Frame1Slot(v1, op), nv2, nv3); + return {op, Frame1Slot(v1, op), nv2, nv3}; } ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const NameExpr* v2, const NameExpr* v3, const NameExpr* v4) { int nv2 = FrameSlot(v2); int nv3 = FrameSlot(v3); int nv4 = FrameSlot(v4); - return ZInstI(op, Frame1Slot(v1, op), nv2, nv3, nv4); + return {op, Frame1Slot(v1, op), nv2, nv3, nv4}; } -ZInstI ZAMCompiler::GenInst(ZOp op, const ConstExpr* ce) { return ZInstI(op, ce); } +ZInstI ZAMCompiler::GenInst(ZOp op, const ConstExpr* ce) { return {op, ce}; } -ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const ConstExpr* ce) { - return ZInstI(op, Frame1Slot(v1, op), ce); -} +ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const ConstExpr* ce) { return {op, Frame1Slot(v1, op), ce}; } -ZInstI ZAMCompiler::GenInst(ZOp op, const ConstExpr* ce, const NameExpr* v1) { - return ZInstI(op, Frame1Slot(v1, op), ce); -} +ZInstI ZAMCompiler::GenInst(ZOp op, const ConstExpr* ce, const NameExpr* v1) { return {op, Frame1Slot(v1, op), ce}; } ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const ConstExpr* ce, const NameExpr* v2) { int nv2 = FrameSlot(v2); - return ZInstI(op, Frame1Slot(v1, op), nv2, ce); + return {op, Frame1Slot(v1, op), nv2, ce}; } ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const NameExpr* v2, const ConstExpr* ce) { int nv2 = FrameSlot(v2); - return ZInstI(op, Frame1Slot(v1, op), nv2, ce); + return {op, Frame1Slot(v1, op), nv2, ce}; } ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const NameExpr* v2, const NameExpr* v3, const ConstExpr* ce) { int nv2 = FrameSlot(v2); int nv3 = FrameSlot(v3); - return ZInstI(op, Frame1Slot(v1, op), nv2, nv3, ce); + return {op, Frame1Slot(v1, op), nv2, nv3, ce}; } ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const NameExpr* v2, const ConstExpr* ce, const NameExpr* v3) { @@ -71,7 +67,7 @@ ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const NameExpr* v2, cons // us from needing to implement a redundant constructor. int nv2 = FrameSlot(v2); int nv3 = FrameSlot(v3); - return ZInstI(op, Frame1Slot(v1, op), nv2, nv3, ce); + return {op, Frame1Slot(v1, op), nv2, nv3, ce}; } ZInstI ZAMCompiler::GenInst(ZOp op, const NameExpr* v1, const ConstExpr* c, int i) { diff --git a/src/spicy/manager.cc b/src/spicy/manager.cc index a18942916e..a850aa4684 100644 --- a/src/spicy/manager.cc +++ b/src/spicy/manager.cc @@ -861,7 +861,7 @@ void Manager::searchModules(const std::string& paths) { detail::Location Manager::makeLocation(const std::string& fname) { auto x = _locations.insert(fname); - return detail::Location(x.first->c_str(), 0, 0, 0, 0); + return {x.first->c_str(), 0, 0, 0, 0}; } void Manager::autoDiscoverModules() { diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 38e02c8073..665efd1bb8 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1170,7 +1170,7 @@ std::optional Supervisor::CreateStem(bool supervisor_mode) sh.pid = pid; sh.stdout_pipe = std::move(fork_res.stdout_pipe); sh.stderr_pipe = std::move(fork_res.stderr_pipe); - return std::optional(std::move(sh)); + return {std::move(sh)}; } static BifEnum::Supervisor::ClusterRole role_str_to_enum(std::string_view r) {