From afc23ae653f435200a8bfa10b3f816cc608319d3 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Thu, 27 Apr 2023 13:40:37 +0200 Subject: [PATCH 01/17] Fix clang-tidy issues, part 1. --- arbor/backends/event.hpp | 8 +-- arbor/backends/event_stream_base.hpp | 2 +- arbor/backends/event_stream_state.hpp | 4 +- arbor/backends/multicore/shared_state.cpp | 15 +++--- arbor/backends/multicore/shared_state.hpp | 14 +++--- arbor/benchmark_cell_group.cpp | 2 +- arbor/cable_cell_param.cpp | 20 ++++---- arbor/communication/dry_run_context.cpp | 6 +-- arbor/cv_policy.cpp | 8 +-- arbor/distributed_context.hpp | 2 +- arbor/fvm_layout.cpp | 6 +-- arbor/iexpr.cpp | 61 +++++++++++------------ arbor/include/arbor/benchmark_cell.hpp | 3 +- arbor/include/arbor/common_types.hpp | 2 +- arbor/include/arbor/cv_policy.hpp | 4 +- arbor/include/arbor/event_generator.hpp | 43 +++++++--------- arbor/include/arbor/morph/isometry.hpp | 6 +-- arbor/include/arbor/morph/primitives.hpp | 6 +-- arbor/include/arbor/recipe.hpp | 15 +++--- arbor/include/arbor/s_expr.hpp | 4 +- arbor/include/arbor/simulation.hpp | 2 +- arbor/include/arbor/util/any_ptr.hpp | 6 ++- arbor/include/arbor/util/expected.hpp | 2 +- arbor/include/arbor/util/extra_traits.hpp | 2 +- arbor/include/arbor/util/unique_any.hpp | 2 +- arbor/label_resolution.cpp | 8 +-- arbor/lif_cell_group.hpp | 20 ++++---- arbor/mc_cell_group.cpp | 42 ++++++++-------- arbor/mechcat.cpp | 12 ++--- arbor/memory/gpu_wrappers.cpp | 4 +- arbor/morph/cv_data.cpp | 2 +- arbor/morph/embed_pwlin.cpp | 6 +-- arbor/morph/locset.cpp | 3 +- arbor/morph/morphology.cpp | 2 +- arbor/morph/region.cpp | 21 ++++---- arbor/morph/stitch.cpp | 4 +- arbor/partition_load_balance.cpp | 1 - arbor/s_expr.cpp | 14 +++--- arbor/simulation.cpp | 29 ++++++----- arbor/threading/threading.cpp | 18 +++---- arbor/threading/threading.hpp | 10 ++-- arbor/util/partition.hpp | 2 +- arborio/cableio.cpp | 4 +- arborio/include/arborio/label_parse.hpp | 5 +- arborio/neurolucida.cpp | 35 +++++-------- arborio/neuroml.cpp | 8 +-- arborio/nml_parse_morphology.cpp | 21 ++++---- arborio/swcio.cpp | 13 +++-- python/strprintf.hpp | 2 +- sup/include/sup/ioutil.hpp | 15 +++--- sup/include/sup/path.hpp | 18 +++---- sup/path.cpp | 2 +- test/unit/test_filter.cpp | 4 +- 53 files changed, 277 insertions(+), 293 deletions(-) diff --git a/arbor/backends/event.hpp b/arbor/backends/event.hpp index c3277af610..cf059216a6 100644 --- a/arbor/backends/event.hpp +++ b/arbor/backends/event.hpp @@ -13,8 +13,8 @@ namespace arb { // Post-synaptic spike events struct target_handle { - cell_local_size_type mech_id; // mechanism type identifier (per cell group). - cell_local_size_type mech_index; // instance of the mechanism + cell_local_size_type mech_id = 0; // mechanism type identifier (per cell group). + cell_local_size_type mech_index = 0; // instance of the mechanism target_handle() = default; target_handle(cell_local_size_type mech_id, cell_local_size_type mech_index): @@ -54,8 +54,8 @@ inline arb_deliverable_event_stream make_event_stream_state(arb_deliverable_even using probe_handle = const arb_value_type*; struct raw_probe_info { - probe_handle handle; // where the to-be-probed value sits - sample_size_type offset; // offset into array to store raw probed value + probe_handle handle = nullptr; // where the to-be-probed value sits + sample_size_type offset = 0; // offset into array to store raw probed value }; struct sample_event { diff --git a/arbor/backends/event_stream_base.hpp b/arbor/backends/event_stream_base.hpp index 616f5454c8..f5bb2f6c34 100644 --- a/arbor/backends/event_stream_base.hpp +++ b/arbor/backends/event_stream_base.hpp @@ -42,7 +42,7 @@ class event_stream_base { index_ += (index_ <= ev_spans_.size() ? 1 : 0); } - auto marked_events() { + auto marked_events() const { using std::begin; using std::end; if (empty()) { diff --git a/arbor/backends/event_stream_state.hpp b/arbor/backends/event_stream_state.hpp index 65fded3717..6277c1b20d 100644 --- a/arbor/backends/event_stream_state.hpp +++ b/arbor/backends/event_stream_state.hpp @@ -11,8 +11,8 @@ template struct event_stream_state { using value_type = EvData; - const value_type* begin_marked; // offset to beginning of marked events - const value_type* end_marked; // offset to one-past-end of marked events + const value_type* begin_marked = nullptr; // offset to beginning of marked events + const value_type* end_marked = nullptr; // offset to one-past-end of marked events std::size_t size() const noexcept { return end_marked - begin_marked; diff --git a/arbor/backends/multicore/shared_state.cpp b/arbor/backends/multicore/shared_state.cpp index 0588a6c393..d7477282c7 100644 --- a/arbor/backends/multicore/shared_state.cpp +++ b/arbor/backends/multicore/shared_state.cpp @@ -262,13 +262,14 @@ std::pair shared_state::voltage_bounds() const { void shared_state::take_samples() { sample_events.mark(); - if (!sample_events.empty()) { - const auto [begin, end] = sample_events.marked_events(); - // Null handles are explicitly permitted, and always give a sample of zero. - for (auto p = begin; poffset] = time; - sample_value[p->offset] = p->handle? *p->handle: 0; - } + const auto& [begin, end] = sample_events.marked_events(); + if (begin == end) return; + if (begin == nullptr || end == nullptr) throw arbor_internal_error{"Invalid sample stream state."}; + // Null handles are explicitly permitted, and always give a sample of zero. + for (auto p = begin; p < end; ++p) { + auto off = p->offset; + sample_time[off] = time; + sample_value[off] = p->handle ? *p->handle : 0; } } diff --git a/arbor/backends/multicore/shared_state.hpp b/arbor/backends/multicore/shared_state.hpp index 6ee1c72d65..c1e3090401 100644 --- a/arbor/backends/multicore/shared_state.hpp +++ b/arbor/backends/multicore/shared_state.hpp @@ -153,13 +153,13 @@ struct ARB_ARBOR_API shared_state: shared_state_base cable_cell_parameter_set::serialize() const { std::vector D; if (init_membrane_potential) { - D.push_back(arb::init_membrane_potential{*this->init_membrane_potential}); + D.emplace_back(arb::init_membrane_potential{*this->init_membrane_potential}); } if (temperature_K) { - D.push_back(arb::temperature_K{*this->temperature_K}); + D.emplace_back(arb::temperature_K{*this->temperature_K}); } if (axial_resistivity) { - D.push_back(arb::axial_resistivity{*this->axial_resistivity}); + D.emplace_back(arb::axial_resistivity{*this->axial_resistivity}); } if (membrane_capacitance) { - D.push_back(arb::membrane_capacitance{*this->membrane_capacitance}); + D.emplace_back(arb::membrane_capacitance{*this->membrane_capacitance}); } for (const auto& [name, data]: ion_data) { if (data.init_int_concentration) { - D.push_back(init_int_concentration{name, *data.init_int_concentration}); + D.emplace_back(init_int_concentration{name, *data.init_int_concentration}); } if (data.init_ext_concentration) { - D.push_back(init_ext_concentration{name, *data.init_ext_concentration}); + D.emplace_back(init_ext_concentration{name, *data.init_ext_concentration}); } if (data.init_reversal_potential) { - D.push_back(init_reversal_potential{name, *data.init_reversal_potential}); + D.emplace_back(init_reversal_potential{name, *data.init_reversal_potential}); } if (data.diffusivity) { - D.push_back(ion_diffusivity{name, *data.diffusivity}); + D.emplace_back(ion_diffusivity{name, *data.diffusivity}); } } for (const auto& [name, mech]: reversal_potential_method) { - D.push_back(ion_reversal_potential_method{name, mech}); + D.emplace_back(ion_reversal_potential_method{name, mech}); } if (discretization) { - D.push_back(*discretization); + D.emplace_back(*discretization); } return D; diff --git a/arbor/communication/dry_run_context.cpp b/arbor/communication/dry_run_context.cpp index affcd77660..be36fd6ff3 100644 --- a/arbor/communication/dry_run_context.cpp +++ b/arbor/communication/dry_run_context.cpp @@ -43,7 +43,7 @@ struct dry_run_context_impl { partition.push_back(static_cast(i*local_size)); } - return gathered_vector(std::move(gathered_spikes), std::move(partition)); + return {std::move(gathered_spikes), std::move(partition)}; } void remote_ctrl_send_continue(const epoch&) const {} void remote_ctrl_send_done() const {} @@ -71,7 +71,7 @@ struct dry_run_context_impl { partition.push_back(static_cast(i*local_size)); } - return gathered_vector(std::move(gathered_gids), std::move(partition)); + return {std::move(gathered_gids), std::move(partition)}; } std::vector> @@ -105,7 +105,7 @@ struct dry_run_context_impl { cell_labels_and_gids gather_cell_labels_and_gids(const cell_labels_and_gids& local_labels_and_gids) const { auto global_ranges = gather_cell_label_range(local_labels_and_gids.label_range); auto gids = gather_gids(local_labels_and_gids.gids); - return cell_labels_and_gids(global_ranges, gids.values()); + return {global_ranges, gids.values()}; } template diff --git a/arbor/cv_policy.cpp b/arbor/cv_policy.cpp index b2962c7fa4..04d9eeaeb1 100644 --- a/arbor/cv_policy.cpp +++ b/arbor/cv_policy.cpp @@ -23,8 +23,8 @@ static auto unique_sum = [](auto&&... lss) { // cv_policy_bar_ represents the result of operator|. struct cv_policy_plus_: cv_policy_base { - cv_policy_plus_(const cv_policy& lhs, const cv_policy& rhs): - lhs_(lhs), rhs_(rhs) {} + cv_policy_plus_(cv_policy lhs, cv_policy rhs): + lhs_(std::move(lhs)), rhs_(std::move(rhs)) {} cv_policy_base_ptr clone() const override { return cv_policy_base_ptr(new cv_policy_plus_(*this)); @@ -49,8 +49,8 @@ ARB_ARBOR_API cv_policy operator+(const cv_policy& lhs, const cv_policy& rhs) { } struct cv_policy_bar_: cv_policy_base { - cv_policy_bar_(const cv_policy& lhs, const cv_policy& rhs): - lhs_(lhs), rhs_(rhs) {} + cv_policy_bar_(cv_policy lhs, cv_policy rhs): + lhs_(std::move(lhs)), rhs_(std::move(rhs)) {} cv_policy_base_ptr clone() const override { return cv_policy_base_ptr(new cv_policy_bar_(*this)); diff --git a/arbor/distributed_context.hpp b/arbor/distributed_context.hpp index c988177d33..7299929d05 100644 --- a/arbor/distributed_context.hpp +++ b/arbor/distributed_context.hpp @@ -134,7 +134,7 @@ class distributed_context { ARB_PP_FOREACH(ARB_INTERFACE_COLLECTIVES_, ARB_COLLECTIVE_TYPES_) - virtual ~interface() {} + virtual ~interface() = default; }; template diff --git a/arbor/fvm_layout.cpp b/arbor/fvm_layout.cpp index 3ae4d707f1..39961cb4d7 100644 --- a/arbor/fvm_layout.cpp +++ b/arbor/fvm_layout.cpp @@ -631,13 +631,13 @@ ARB_ARBOR_API fvm_voltage_interpolant fvm_interpolate_voltage(const cable_cell& msize_t bid = site.branch; arb_assert(vrefs.proximal.loc.possite.pos; - mcable rs_span = flip_rs? mcable{bid, site.pos, vrefs.proximal.loc.pos} - : mcable{bid, vrefs.proximal.loc.pos, site.pos}; + auto rs_span = flip_rs ? mcable{bid, site.pos, vrefs.proximal.loc.pos} + : mcable{bid, vrefs.proximal.loc.pos, site.pos}; double rs_resistance = embedding.integrate_ixa(rs_span, D.axial_resistivity[0].at(bid)); if (flip_rs) { diff --git a/arbor/iexpr.cpp b/arbor/iexpr.cpp index eaaba7cd07..0544b17158 100644 --- a/arbor/iexpr.cpp +++ b/arbor/iexpr.cpp @@ -218,7 +218,7 @@ struct interpolation: public iexpr_interface { if (!d2) return 0.0; const auto sum = d1.value() + d2.value(); - if (!sum) return (prox_v + dist_v) * 0.5; + if (0 == sum) return (prox_v + dist_v) * 0.5; return prox_v * (d2.value() / sum) + dist_v * (d1.value() / sum); } @@ -336,13 +336,13 @@ struct log: public iexpr_interface { iexpr::iexpr(double value) { *this = iexpr::scalar(value); } -iexpr iexpr::scalar(double value) { return iexpr(iexpr_type::scalar, std::make_tuple(value)); } +iexpr iexpr::scalar(double value) { return {iexpr_type::scalar, std::make_tuple(value)}; } iexpr iexpr::pi() { return iexpr::scalar(math::pi); } iexpr iexpr::distance(double scale, locset loc) { - return iexpr( - iexpr_type::distance, std::make_tuple(scale, std::variant(std::move(loc)))); + return { + iexpr_type::distance, std::make_tuple(scale, std::variant(std::move(loc)))}; } iexpr iexpr::distance(locset loc) { @@ -350,8 +350,8 @@ iexpr iexpr::distance(locset loc) { } iexpr iexpr::distance(double scale, region reg) { - return iexpr( - iexpr_type::distance, std::make_tuple(scale, std::variant(std::move(reg)))); + return { + iexpr_type::distance, std::make_tuple(scale, std::variant(std::move(reg)))}; } iexpr iexpr::distance(region reg) { @@ -359,8 +359,8 @@ iexpr iexpr::distance(region reg) { } iexpr iexpr::proximal_distance(double scale, locset loc) { - return iexpr(iexpr_type::proximal_distance, - std::make_tuple(scale, std::variant(std::move(loc)))); + return {iexpr_type::proximal_distance, + std::make_tuple(scale, std::variant(std::move(loc)))}; } iexpr iexpr::proximal_distance(locset loc) { @@ -368,8 +368,8 @@ iexpr iexpr::proximal_distance(locset loc) { } iexpr iexpr::proximal_distance(double scale, region reg) { - return iexpr(iexpr_type::proximal_distance, - std::make_tuple(scale, std::variant(std::move(reg)))); + return {iexpr_type::proximal_distance, + std::make_tuple(scale, std::variant(std::move(reg)))}; } iexpr iexpr::proximal_distance(region reg) { @@ -377,8 +377,8 @@ iexpr iexpr::proximal_distance(region reg) { } iexpr iexpr::distal_distance(double scale, locset loc) { - return iexpr(iexpr_type::distal_distance, - std::make_tuple(scale, std::variant(std::move(loc)))); + return {iexpr_type::distal_distance, + std::make_tuple(scale, std::variant(std::move(loc)))}; } iexpr iexpr::distal_distance(locset loc) { @@ -386,8 +386,7 @@ iexpr iexpr::distal_distance(locset loc) { } iexpr iexpr::distal_distance(double scale, region reg) { - return iexpr(iexpr_type::distal_distance, - std::make_tuple(scale, std::variant(std::move(reg)))); + return {iexpr_type::distal_distance, std::make_tuple(scale, std::variant(std::move(reg)))}; } iexpr iexpr::distal_distance(region reg) { @@ -398,61 +397,59 @@ iexpr iexpr::interpolation(double prox_value, locset prox_list, double dist_value, locset dist_list) { - return iexpr(iexpr_type::interpolation, + return {iexpr_type::interpolation, std::make_tuple(prox_value, std::variant(std::move(prox_list)), dist_value, - std::variant(std::move(dist_list)))); + std::variant(std::move(dist_list)))}; } iexpr iexpr::interpolation(double prox_value, region prox_list, double dist_value, region dist_list) { - return iexpr(iexpr_type::interpolation, + return {iexpr_type::interpolation, std::make_tuple(prox_value, std::variant(std::move(prox_list)), dist_value, - std::variant(std::move(dist_list)))); + std::variant(std::move(dist_list)))}; } -iexpr iexpr::radius(double scale) { return iexpr(iexpr_type::radius, std::make_tuple(scale)); } +iexpr iexpr::radius(double scale) { return {iexpr_type::radius, std::make_tuple(scale)}; } iexpr iexpr::radius() { return iexpr::radius(1.0); } -iexpr iexpr::diameter(double scale) { return iexpr(iexpr_type::diameter, std::make_tuple(scale)); } +iexpr iexpr::diameter(double scale) { return {iexpr_type::diameter, std::make_tuple(scale)}; } iexpr iexpr::diameter() { return iexpr::diameter(1.0); } iexpr iexpr::add(iexpr left, iexpr right) { - return iexpr(iexpr_type::add, std::make_tuple(std::move(left), std::move(right))); + return {iexpr_type::add, std::make_tuple(std::move(left), std::move(right))}; } iexpr iexpr::sub(iexpr left, iexpr right) { - return iexpr(iexpr_type::sub, std::make_tuple(std::move(left), std::move(right))); + return {iexpr_type::sub, std::make_tuple(std::move(left), std::move(right))}; } iexpr iexpr::mul(iexpr left, iexpr right) { - return iexpr(iexpr_type::mul, std::make_tuple(std::move(left), std::move(right))); + return {iexpr_type::mul, std::make_tuple(std::move(left), std::move(right))}; } iexpr iexpr::div(iexpr left, iexpr right) { - return iexpr(iexpr_type::div, std::make_tuple(std::move(left), std::move(right))); + return {iexpr_type::div, std::make_tuple(std::move(left), std::move(right))}; } -iexpr iexpr::exp(iexpr value) { return iexpr(iexpr_type::exp, std::make_tuple(std::move(value))); } +iexpr iexpr::exp(iexpr value) { return {iexpr_type::exp, std::make_tuple(std::move(value))}; } -iexpr iexpr::step_right(iexpr value) { return iexpr(iexpr_type::step_right, std::make_tuple(std::move(value))); } +iexpr iexpr::step_right(iexpr value) { return {iexpr_type::step_right, std::make_tuple(std::move(value))}; } -iexpr iexpr::step_left(iexpr value) { return iexpr(iexpr_type::step_left, std::make_tuple(std::move(value))); } +iexpr iexpr::step_left(iexpr value) { return {iexpr_type::step_left, std::make_tuple(std::move(value))}; } -iexpr iexpr::step(iexpr value) { return iexpr(iexpr_type::step, std::make_tuple(std::move(value))); } +iexpr iexpr::step(iexpr value) { return {iexpr_type::step, std::make_tuple(std::move(value))}; } -iexpr iexpr::log(iexpr value) { return iexpr(iexpr_type::log, std::make_tuple(std::move(value))); } +iexpr iexpr::log(iexpr value) { return {iexpr_type::log, std::make_tuple(std::move(value))}; } -iexpr iexpr::named(std::string name) { - return iexpr(iexpr_type::named, std::make_tuple(std::move(name))); -} +iexpr iexpr::named(std::string name) { return {iexpr_type::named, std::make_tuple(std::move(name))}; } iexpr_ptr thingify(const iexpr& expr, const mprovider& m) { switch (expr.type()) { diff --git a/arbor/include/arbor/benchmark_cell.hpp b/arbor/include/arbor/benchmark_cell.hpp index 30719fd947..46e50763d8 100644 --- a/arbor/include/arbor/benchmark_cell.hpp +++ b/arbor/include/arbor/benchmark_cell.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace arb { @@ -21,7 +22,7 @@ struct ARB_SYMBOL_VISIBLE benchmark_cell { benchmark_cell() = delete; benchmark_cell(cell_tag_type source, cell_tag_type target, schedule seq, double ratio): - source(source), target(target), time_sequence(seq), realtime_ratio(ratio) {}; + source(std::move(source)), target(std::move(target)), time_sequence(std::move(seq)), realtime_ratio(ratio) {}; }; } // namespace arb diff --git a/arbor/include/arbor/common_types.hpp b/arbor/include/arbor/common_types.hpp index 9db14ef764..3491587ef8 100644 --- a/arbor/include/arbor/common_types.hpp +++ b/arbor/include/arbor/common_types.hpp @@ -82,7 +82,7 @@ struct cell_local_label_type { cell_tag_type tag; lid_selection_policy policy; - cell_local_label_type(cell_tag_type tag, lid_selection_policy policy=lid_selection_policy::assert_univalent): + cell_local_label_type(cell_tag_type tag, lid_selection_policy policy=lid_selection_policy::assert_univalent) noexcept: tag(std::move(tag)), policy(policy) {} }; diff --git a/arbor/include/arbor/cv_policy.hpp b/arbor/include/arbor/cv_policy.hpp index a1a5077cf1..dd26aa69b6 100644 --- a/arbor/include/arbor/cv_policy.hpp +++ b/arbor/include/arbor/cv_policy.hpp @@ -65,7 +65,7 @@ struct cv_policy_base { virtual locset cv_boundary_points(const cable_cell& cell) const = 0; virtual region domain() const = 0; virtual std::unique_ptr clone() const = 0; - virtual ~cv_policy_base() {} + virtual ~cv_policy_base() = default; virtual std::ostream& print(std::ostream&) = 0; }; @@ -135,7 +135,7 @@ struct ARB_ARBOR_API cv_policy_explicit: cv_policy_base { struct ARB_ARBOR_API cv_policy_single: cv_policy_base { explicit cv_policy_single(region domain = reg::all()): - domain_(domain) {} + domain_(std::move(domain)) {} cv_policy_base_ptr clone() const override; locset cv_boundary_points(const cable_cell&) const override; diff --git a/arbor/include/arbor/event_generator.hpp b/arbor/include/arbor/event_generator.hpp index c378ef7d03..690911d09f 100644 --- a/arbor/include/arbor/event_generator.hpp +++ b/arbor/include/arbor/event_generator.hpp @@ -99,36 +99,30 @@ struct event_generator { // Simplest generator: just do nothing inline -event_generator empty_generator( - cell_local_label_type target, - float weight) -{ - return event_generator(std::move(target), weight, schedule()); +event_generator empty_generator(cell_local_label_type target, + float weight) { + return {std::move(target), weight, schedule()}; } // Generate events at integer multiples of dt that lie between tstart and tstop. -inline event_generator regular_generator( - cell_local_label_type target, - float weight, - time_type tstart, - time_type dt, - time_type tstop=terminal_time) -{ - return event_generator(std::move(target), weight, regular_schedule(tstart, dt, tstop)); +inline event_generator regular_generator(cell_local_label_type target, + float weight, + time_type tstart, + time_type dt, + time_type tstop=terminal_time) { + return {std::move(target), weight, regular_schedule(tstart, dt, tstop)}; } template -inline event_generator poisson_generator( - cell_local_label_type target, - float weight, - time_type tstart, - time_type rate_kHz, - const RNG& rng, - time_type tstop=terminal_time) -{ - return event_generator(std::move(target), weight, poisson_schedule(tstart, rate_kHz, rng, tstop)); +inline event_generator poisson_generator(cell_local_label_type target, + float weight, + time_type tstart, + time_type rate_kHz, + const RNG& rng, + time_type tstop=terminal_time) { + return {std::move(target), weight, poisson_schedule(tstart, rate_kHz, rng, tstop)}; } @@ -137,9 +131,8 @@ inline event_generator poisson_generator( template inline event_generator explicit_generator(cell_local_label_type target, float weight, - const S& s) -{ - return event_generator(std::move(target), weight, explicit_schedule(s)); + const S& s) { + return {std::move(target), weight, explicit_schedule(s)}; } } // namespace arb diff --git a/arbor/include/arbor/morph/isometry.hpp b/arbor/include/arbor/morph/isometry.hpp index cb06ee28dd..54d958917f 100644 --- a/arbor/include/arbor/morph/isometry.hpp +++ b/arbor/include/arbor/morph/isometry.hpp @@ -15,7 +15,7 @@ struct ARB_ARBOR_API isometry { // as applied to absolute coordinates (composed by addition). friend isometry operator*(const isometry& a, const isometry& b) { - return isometry(b.q_*a.q_, a.tx_+b.tx_, a.ty_+b.ty_, a.tz_+b.tz_); + return {b.q_*a.q_, a.tx_+b.tx_, a.ty_+b.ty_, a.tz_+b.tz_}; } template @@ -37,7 +37,7 @@ struct ARB_ARBOR_API isometry { public: static isometry translate(double x, double y, double z) { - return isometry(quaternion{1, 0, 0, 0}, x, y, z); + return {quaternion{1, 0, 0, 0}, x, y, z}; } template @@ -50,7 +50,7 @@ struct ARB_ARBOR_API isometry { double norm = std::sqrt(ax*ax+ay*ay+az*az); double vscale = std::sin(theta/2)/norm; - return isometry(quaternion{std::cos(theta/2), ax*vscale, ay*vscale, az*vscale}, 0, 0, 0); + return {quaternion{std::cos(theta/2), ax*vscale, ay*vscale, az*vscale}, 0, 0, 0}; } template diff --git a/arbor/include/arbor/morph/primitives.hpp b/arbor/include/arbor/morph/primitives.hpp index 9d75060df2..fd98f4510d 100644 --- a/arbor/include/arbor/morph/primitives.hpp +++ b/arbor/include/arbor/morph/primitives.hpp @@ -87,12 +87,12 @@ ARB_ARBOR_API mlocation_list support(mlocation_list); struct ARB_SYMBOL_VISIBLE mcable { // The id of the branch on which the cable lies. - msize_t branch; + msize_t branch = 0; // Relative location of the end points on the branch. // 0 ≤ prox_pos ≤ dist_pos ≤ 1 - double prox_pos; // ∈ [0,1] - double dist_pos; // ∈ [0,1] + double prox_pos = 0; // ∈ [0,1] + double dist_pos = 0; // ∈ [0,1] friend mlocation prox_loc(const mcable& c) { return {c.branch, c.prox_pos}; diff --git a/arbor/include/arbor/recipe.hpp b/arbor/include/arbor/recipe.hpp index 65ad9e49d5..61a03428ba 100644 --- a/arbor/include/arbor/recipe.hpp +++ b/arbor/include/arbor/recipe.hpp @@ -22,7 +22,8 @@ struct probe_info { probe_info(probe_info&&) = default; // Implicit ctor uses tag of zero. - template + template >> // otherwise, we'd hide ctors above probe_info(X&& x, probe_tag tag = 0): tag(tag), address(std::forward(x)) {} }; @@ -68,14 +69,14 @@ struct ARB_ARBOR_API has_gap_junctions { virtual std::vector gap_junctions_on(cell_gid_type) const { return {}; } - virtual ~has_gap_junctions() {} + virtual ~has_gap_junctions() = default; }; struct ARB_ARBOR_API has_synapses { virtual std::vector connections_on(cell_gid_type) const { return {}; } - virtual ~has_synapses() {} + virtual ~has_synapses() = default; }; struct ARB_ARBOR_API has_external_synapses { @@ -88,14 +89,14 @@ struct ARB_ARBOR_API has_probes { virtual std::vector get_probes(cell_gid_type gid) const { return {}; } - virtual ~has_probes() {} + virtual ~has_probes() = default; }; struct ARB_ARBOR_API has_generators { virtual std::vector event_generators(cell_gid_type) const { return {}; } - virtual ~has_generators() {} + virtual ~has_generators() = default; }; // Toppings allow updating a simulation @@ -103,7 +104,7 @@ struct ARB_ARBOR_API connectivity: public has_synapses, has_external_synapses, has_generators { - virtual ~connectivity() {} + ~connectivity() override = default; }; // Recipes allow building a simulation by lazy queries @@ -117,7 +118,7 @@ struct ARB_ARBOR_API recipe: public has_gap_junctions, has_probes, connectivity // Global property type will be specific to given cell kind. virtual std::any get_global_properties(cell_kind) const { return std::any{}; }; - virtual ~recipe() {} + ~recipe() override = default; }; } // namespace arb diff --git a/arbor/include/arbor/s_expr.hpp b/arbor/include/arbor/s_expr.hpp index c5c4f51fa1..85f62d3eb9 100644 --- a/arbor/include/arbor/s_expr.hpp +++ b/arbor/include/arbor/s_expr.hpp @@ -208,13 +208,13 @@ struct ARB_ARBOR_API s_expr { using pair_type = s_pair>; std::variant state = token{{0,0}, tok::nil, "()"}; - s_expr(const s_expr& s): state(s.state) {} + s_expr(const s_expr& s) = default; s_expr() = default; s_expr(token t): state(std::move(t)) {} s_expr(s_expr l, s_expr r): state(pair_type(std::move(l), std::move(r))) {} - s_expr& operator=(const s_expr& s) { state = s.state; return *this; } + s_expr& operator=(const s_expr& s) = default; explicit s_expr(std::string s): s_expr(token{{0,0}, tok::string, std::move(s)}) {} diff --git a/arbor/include/arbor/simulation.hpp b/arbor/include/arbor/simulation.hpp index 844257f39d..65724970fd 100644 --- a/arbor/include/arbor/simulation.hpp +++ b/arbor/include/arbor/simulation.hpp @@ -153,7 +153,7 @@ class ARB_ARBOR_API simulation_builder { } simulation build(context ctx, domain_decomposition const& decomp) const { - return simulation(rec_, ctx, decomp, seed_); + return {rec_, ctx, decomp, seed_}; } private: diff --git a/arbor/include/arbor/util/any_ptr.hpp b/arbor/include/arbor/util/any_ptr.hpp index 80f5273c6d..0ad007a329 100644 --- a/arbor/include/arbor/util/any_ptr.hpp +++ b/arbor/include/arbor/util/any_ptr.hpp @@ -72,8 +72,10 @@ struct ARB_SYMBOL_VISIBLE any_ptr { } any_ptr& operator=(const any_ptr& other) noexcept { - type_ptr_ = other.type_ptr_; - ptr_ = other.ptr_; + if (&other != this) { + type_ptr_ = other.type_ptr_; + ptr_ = other.ptr_; + } return *this; } diff --git a/arbor/include/arbor/util/expected.hpp b/arbor/include/arbor/util/expected.hpp index 9d860f6536..836b072db1 100644 --- a/arbor/include/arbor/util/expected.hpp +++ b/arbor/include/arbor/util/expected.hpp @@ -45,7 +45,7 @@ struct bad_expected_access; template <> struct bad_expected_access: std::exception { bad_expected_access() = default; - virtual const char* what() const noexcept override { return "bad expected access"; } + const char* what() const noexcept override { return "bad expected access"; } }; template diff --git a/arbor/include/arbor/util/extra_traits.hpp b/arbor/include/arbor/util/extra_traits.hpp index 62653158f5..343710cb41 100644 --- a/arbor/include/arbor/util/extra_traits.hpp +++ b/arbor/include/arbor/util/extra_traits.hpp @@ -7,7 +7,7 @@ namespace util { template struct remove_cvref { - typedef std::remove_cv_t> type; + using type = std::remove_cv_t>; }; template diff --git a/arbor/include/arbor/util/unique_any.hpp b/arbor/include/arbor/util/unique_any.hpp index 9cbcf67d14..97f3bee5d5 100644 --- a/arbor/include/arbor/util/unique_any.hpp +++ b/arbor/include/arbor/util/unique_any.hpp @@ -106,7 +106,7 @@ class ARB_SYMBOL_VISIBLE unique_any { template struct model: public interface { - ~model() = default; + ~model() override = default; model(const T& other): value(other) {} model(T&& other): value(std::move(other)) {} diff --git a/arbor/label_resolution.cpp b/arbor/label_resolution.cpp index dd928098b6..f26604c6a2 100644 --- a/arbor/label_resolution.cpp +++ b/arbor/label_resolution.cpp @@ -157,8 +157,8 @@ resolver::state_variant resolver::construct_state(lid_selection_policy pol) { case lid_selection_policy::round_robin_halt: return round_robin_halt_state(); case lid_selection_policy::assert_univalent: - return assert_univalent_state(); - default: return assert_univalent_state(); + default: + return assert_univalent_state(); } } @@ -169,8 +169,8 @@ resolver::state_variant resolver::construct_state(lid_selection_policy pol, cell case lid_selection_policy::round_robin_halt: return round_robin_halt_state(state); case lid_selection_policy::assert_univalent: - return assert_univalent_state(); - default: return assert_univalent_state(); + default: + return assert_univalent_state(); } } diff --git a/arbor/lif_cell_group.hpp b/arbor/lif_cell_group.hpp index f0fcb665a4..09c5ac20c1 100644 --- a/arbor/lif_cell_group.hpp +++ b/arbor/lif_cell_group.hpp @@ -16,7 +16,7 @@ namespace arb { -class ARB_ARBOR_API lif_cell_group: public cell_group { +class ARB_ARBOR_API lif_cell_group final: public cell_group { public: using value_type = double; @@ -25,20 +25,20 @@ class ARB_ARBOR_API lif_cell_group: public cell_group { // Constructor containing gid of first cell in a group and a container of all cells. lif_cell_group(const std::vector& gids, const recipe& rec, cell_label_range& cg_sources, cell_label_range& cg_targets); - virtual cell_kind get_cell_kind() const override; - virtual void reset() override; - virtual void advance(epoch epoch, time_type dt, const event_lane_subrange& events) override; + cell_kind get_cell_kind() const override; + void reset() override; + void advance(epoch epoch, time_type dt, const event_lane_subrange& events) override; - virtual const std::vector& spikes() const override; - virtual void clear_spikes() override; + const std::vector& spikes() const override; + void clear_spikes() override; // Sampler association methods below should be thread-safe, as they might be invoked // from a sampler call back called from a different cell group running on a different thread. - virtual void add_sampler(sampler_association_handle, cell_member_predicate, schedule, sampler_function) override; - virtual void remove_sampler(sampler_association_handle) override; - virtual void remove_all_samplers() override; + void add_sampler(sampler_association_handle, cell_member_predicate, schedule, sampler_function) override; + void remove_sampler(sampler_association_handle) override; + void remove_all_samplers() override; - virtual std::vector get_probe_metadata(cell_member_type) const override; + std::vector get_probe_metadata(cell_member_type) const override; private: enum class lif_probe_kind { voltage }; diff --git a/arbor/mc_cell_group.cpp b/arbor/mc_cell_group.cpp index 2c6cb3bfdf..0f265f49e8 100644 --- a/arbor/mc_cell_group.cpp +++ b/arbor/mc_cell_group.cpp @@ -180,8 +180,8 @@ void run_samples( std::vector& sample_records, fvm_probe_scratch& scratch) { - const sample_size_type n_raw_per_sample = p.raw_handles.size(); - sample_size_type n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; + auto n_raw_per_sample = p.raw_handles.size(); + auto n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; arb_assert((sc.end_offset-sc.begin_offset)==n_sample*n_raw_per_sample); auto& sample_ranges = std::get>(scratch); @@ -190,7 +190,7 @@ void run_samples( for (sample_size_type j = 0; j& sample_records, fvm_probe_scratch& scratch) { - const sample_size_type n_raw_per_sample = p.raw_handles.size(); - sample_size_type n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; + auto n_raw_per_sample = p.raw_handles.size(); + auto n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; arb_assert((sc.end_offset-sc.begin_offset)==n_sample*n_raw_per_sample); arb_assert((unsigned)n_raw_per_sample==p.weight.size()); @@ -232,7 +232,7 @@ void run_samples( const double* tmp_ptr = tmp.data(); for (sample_size_type j = 0; j& sample_records, fvm_probe_scratch& scratch) { - const sample_size_type n_raw_per_sample = p.raw_handles.size(); - const sample_size_type n_interp_per_sample = n_raw_per_sample/2; - sample_size_type n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; + auto n_raw_per_sample = p.raw_handles.size(); + auto n_interp_per_sample = n_raw_per_sample/2; + auto n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; arb_assert((sc.end_offset-sc.begin_offset)==n_sample*n_raw_per_sample); arb_assert((unsigned)n_interp_per_sample==p.coef[0].size()); arb_assert((unsigned)n_interp_per_sample==p.coef[1].size()); @@ -279,7 +279,7 @@ void run_samples( const double* tmp_ptr = tmp.data(); for (sample_size_type j = 0; j& sample_records, fvm_probe_scratch& scratch) { - const sample_size_type n_raw_per_sample = p.raw_handles.size(); - sample_size_type n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; + auto n_raw_per_sample = p.raw_handles.size(); + auto n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; arb_assert((sc.end_offset-sc.begin_offset)==n_sample*n_raw_per_sample); const auto n_cable = p.metadata.size(); @@ -327,7 +327,7 @@ void run_samples( const double* v = raw_samples+offset; for (auto cv: util::make_span(n_cv)) { - arb_index_type parent_cv = p.cv_parent[cv]; + auto parent_cv = p.cv_parent[cv]; if (parent_cv+1==0) continue; double cond = p.cv_parent_cond[cv]; @@ -354,7 +354,7 @@ void run_samples( tmp_base[cable_i] -= cv_stim_I*p.weight[cable_i]; } } - sample_ranges.push_back({tmp_base, tmp_base+n_cable}); + sample_ranges.emplace_back(tmp_base, tmp_base+n_cable); } const auto& csample_ranges = sample_ranges; @@ -367,13 +367,11 @@ void run_samples( } // Generic run_samples dispatches on probe info variant type. -void run_samples( - const sampler_call_info& sc, - const arb_value_type* raw_times, - const arb_value_type* raw_samples, - std::vector& sample_records, - fvm_probe_scratch& scratch) -{ +void run_samples(const sampler_call_info& sc, + const arb_value_type* raw_times, + const arb_value_type* raw_samples, + std::vector& sample_records, + fvm_probe_scratch& scratch) { std::visit([&](auto& x) {run_samples(x, sc, raw_times, raw_samples, sample_records, scratch); }, sc.pdata_ptr->info); } @@ -445,7 +443,7 @@ void mc_cell_group::advance(epoch ep, time_type dt, const event_lane_subrange& e for (auto& [sk, sa]: sampler_map_) { if (sa.probeset_ids.empty()) continue; // No need to make any schedule auto sample_times = util::make_range(sa.sched.events(tstart, ep.t1)); - sample_size_type n_times = sample_times.size(); + auto n_times = static_cast(sample_times.size()); if (n_times == 0) continue; max_samples_per_call = std::max(max_samples_per_call, n_times); for (const cell_member_type& pid: sa.probeset_ids) { diff --git a/arbor/mechcat.cpp b/arbor/mechcat.cpp index 58dfd90264..02c537a115 100644 --- a/arbor/mechcat.cpp +++ b/arbor/mechcat.cpp @@ -284,7 +284,7 @@ struct catalogue_state { mechanism_info_ptr new_info; if (auto parent_info = info(parent)) { - new_info.reset(new mechanism_info(parent_info.value())); + new_info = std::make_unique(parent_info.value()); } else { return unexpected(parent_info.error()); @@ -396,15 +396,15 @@ struct catalogue_state { } if (is_ion(k)) { - ion_remap.push_back({k, v}); + ion_remap.emplace_back(k, v); } else { - char* end = 0; - double v_value = std::strtod(v.c_str(), &end); + char* end = nullptr; + auto v_value = std::strtod(v.c_str(), &end); if (!end || *end) { return unexpected_exception_ptr(invalid_parameter_value(name, k, v)); } - global_params.push_back({k, v_value}); + global_params.emplace_back(k, v_value); } } @@ -535,7 +535,7 @@ mechanism_catalogue::mechanism_catalogue(const mechanism_catalogue& other): mechanism_catalogue& mechanism_catalogue::operator=(const mechanism_catalogue& other) { if (this != &other) { - state_.reset(new catalogue_state(*other.state_)); + state_ = std::make_unique(*other.state_); } return *this; } diff --git a/arbor/memory/gpu_wrappers.cpp b/arbor/memory/gpu_wrappers.cpp index 3cf6ff295c..fdb76ceb6d 100644 --- a/arbor/memory/gpu_wrappers.cpp +++ b/arbor/memory/gpu_wrappers.cpp @@ -105,7 +105,7 @@ void gpu_memcpy_h2d_async(void* dest, const void* src, std::size_t n) { void* gpu_host_register(void* ptr, std::size_t size) { NOGPU; - return 0; + return nullptr; } void gpu_host_unregister(void* ptr) { @@ -114,7 +114,7 @@ void gpu_host_unregister(void* ptr) { void* gpu_malloc(std::size_t n) { NOGPU; - return 0; + return nullptr; } void gpu_free(void* ptr) { diff --git a/arbor/morph/cv_data.cpp b/arbor/morph/cv_data.cpp index ec4d68e762..cf3927e9ea 100644 --- a/arbor/morph/cv_data.cpp +++ b/arbor/morph/cv_data.cpp @@ -146,7 +146,7 @@ ARB_ARBOR_API std::optional cv_data(const cable_cell& cell) { using impl_ptr = std::unique_ptr; impl_ptr make_impl(cell_cv_data_impl* c) { - return impl_ptr(c, [](cell_cv_data_impl* p){delete p;}); + return {c, [](cell_cv_data_impl* p){delete p;}}; } cell_cv_data::cell_cv_data(const cable_cell& cell, const locset& lset): diff --git a/arbor/morph/embed_pwlin.cpp b/arbor/morph/embed_pwlin.cpp index 474cabf9fb..a078421b9b 100644 --- a/arbor/morph/embed_pwlin.cpp +++ b/arbor/morph/embed_pwlin.cpp @@ -227,7 +227,7 @@ mcable_list data_cmp(const std::vector>& f_on_branch, msize_t b continue; } if (op(left_val, val) && op(right_val, val)) { - L.push_back({bid, left, right}); + L.emplace_back(mcable{bid, left, right}); continue; } @@ -235,11 +235,11 @@ mcable_list data_cmp(const std::vector>& f_on_branch, msize_t b auto edge = math::lerp(left, right, cable_loc); if (op(left_val, val)) { - L.push_back({bid, left, edge}); + L.emplace_back(mcable{bid, left, edge}); continue; } if (!op(left_val, val)) { - L.push_back({bid, edge, right}); + L.emplace_back(mcable{bid, edge, right}); continue; } } diff --git a/arbor/morph/locset.cpp b/arbor/morph/locset.cpp index 2cd745f096..f9a956839a 100644 --- a/arbor/morph/locset.cpp +++ b/arbor/morph/locset.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "util/cbrng.hpp" #include "util/partition.hpp" @@ -663,7 +664,7 @@ std::ostream& operator<<(std::ostream& o, const lsup_& x) { // are also in the region. struct lrestrict_: locset_tag { - explicit lrestrict_(const locset& l, const region& r): ls{l}, reg{r} {} + explicit lrestrict_(locset l, region r): ls{std::move(l)}, reg{std::move(r)} {} locset ls; region reg; }; diff --git a/arbor/morph/morphology.cpp b/arbor/morph/morphology.cpp index f57d3386c6..e36f341932 100644 --- a/arbor/morph/morphology.cpp +++ b/arbor/morph/morphology.cpp @@ -428,7 +428,7 @@ ARB_ARBOR_API std::vector components(const morphology& m, const mextent } else { index = component_cables.size(); - component_cables.push_back({}); + component_cables.emplace_back(); } component_cables[index].push_back(c); diff --git a/arbor/morph/region.cpp b/arbor/morph/region.cpp index 4db56deb59..3d6fed9645 100644 --- a/arbor/morph/region.cpp +++ b/arbor/morph/region.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -97,7 +98,7 @@ mextent thingify_(const cable_list_& reg, const mprovider& p) { if (last_branch>=p.morphology().num_branches()) { throw no_such_branch(last_branch); } - return mextent(reg.cables); + return {reg.cables}; } std::ostream& operator<<(std::ostream& o, const cable_list_& x) { @@ -157,7 +158,7 @@ mextent thingify_(const tagged_& reg, const mprovider& p) { } // NOTE: this should always be true since we traverse things in order. arb_assert(util::is_sorted(cables)); - return mextent(cables); + return {cables}; } std::ostream& operator<<(std::ostream& o, const tagged_& t) { @@ -184,7 +185,7 @@ mextent thingify_(const segment_& reg, const mprovider& p) { } mcable_list cables = {e.segment(id)}; - return mextent(cables); + return {cables}; } std::ostream& operator<<(std::ostream& o, const segment_& reg) { @@ -204,9 +205,9 @@ mextent thingify_(const all_&, const mprovider& p) { mcable_list branches; branches.reserve(nb); for (auto i: util::make_span(nb)) { - branches.push_back({i,0,1}); + branches.emplace_back(mcable{i, 0, 1}); } - return mextent(branches); + return {branches}; } std::ostream& operator<<(std::ostream& o, const all_& t) { @@ -279,7 +280,7 @@ mextent thingify_(const distal_interval_& reg, const mprovider& p) { } util::sort(L); - return mextent(L); + return {L}; } std::ostream& operator<<(std::ostream& o, const distal_interval_& d) { @@ -336,7 +337,7 @@ mextent thingify_(const proximal_interval_& reg, const mprovider& p) { } util::sort(L); - return mextent(L); + return {L}; } std::ostream& operator<<(std::ostream& o, const proximal_interval_& d) { @@ -444,7 +445,7 @@ mextent projection_cmp(const mprovider& p, double v, comp_op op) { for (auto i: util::make_span(m.num_branches())) { util::append(L, e.projection_cmp(i, val, op)); } - return mextent(L); + return {L}; } // Region with all segments with projection less than val @@ -567,7 +568,7 @@ std::ostream& operator<<(std::ostream& o, const named_& x) { // Adds all cover points to a region. // Ensures that all valid representations of all fork points in the region are included. struct super_: region_tag { - explicit super_(const region& rg): reg{rg} {} + explicit super_(region rg): reg{std::move(rg)} {} region reg; }; @@ -701,7 +702,7 @@ mextent thingify_(const reg_not& P, const mprovider& p) { } } - return mextent(result); + return {result}; } std::ostream& operator<<(std::ostream& o, const reg_not& x) { diff --git a/arbor/morph/stitch.cpp b/arbor/morph/stitch.cpp index 341ee71417..29b5cbbec9 100644 --- a/arbor/morph/stitch.cpp +++ b/arbor/morph/stitch.cpp @@ -169,7 +169,7 @@ stitched_morphology::stitched_morphology(const stitch_builder& builder): stitched_morphology::stitched_morphology(stitched_morphology&& other) = default; arb::morphology stitched_morphology::morphology() const { - return arb::morphology(impl_->stree); + return {impl_->stree}; } label_dict stitched_morphology::labels(const std::string& prefix) const { @@ -206,7 +206,7 @@ std::vector stitched_morphology::segments(const std::string& id) const auto seg_ids = util::transform_view(util::make_range(impl_->id_to_segs.equal_range(id)), util::second); if (seg_ids.empty()) throw no_such_stitch(id); - return std::vector(begin(seg_ids), end(seg_ids)); + return {begin(seg_ids), end(seg_ids)}; } stitched_morphology::~stitched_morphology() = default; diff --git a/arbor/partition_load_balance.cpp b/arbor/partition_load_balance.cpp index 8718c743d1..01874f6b50 100644 --- a/arbor/partition_load_balance.cpp +++ b/arbor/partition_load_balance.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "cell_group_factory.hpp" diff --git a/arbor/s_expr.cpp b/arbor/s_expr.cpp index 70da5c7c42..71fbc2692c 100644 --- a/arbor/s_expr.cpp +++ b/arbor/s_expr.cpp @@ -88,15 +88,15 @@ static std::unordered_map keyword_to_tok = { }; class lexer { - const char* line_start_; - const char* stream_; - unsigned line_; + const char* line_start_ = nullptr; + const char* stream_ = nullptr; + unsigned line_{0}; token token_; public: lexer(const char* begin): - line_start_(begin), stream_(begin), line_(0) + line_start_(begin), stream_(begin) { // Prime the first token. parse(); @@ -115,7 +115,7 @@ class lexer { private: src_location loc() const { - return src_location(line_+1, stream_-line_start_+1); + return {line_+1, static_cast(stream_-line_start_+1)}; } bool empty() const { @@ -268,7 +268,7 @@ class lexer { symbol += c; ++stream_; - while(1) { + for(;;) { c = *stream_; if(is_valid_symbol_char(c)) { @@ -321,7 +321,7 @@ class lexer { str += c; ++stream_; - while(1) { + for(;;) { c = *stream_; if (std::isdigit(c)) { str += c; diff --git a/arbor/simulation.cpp b/arbor/simulation.cpp index 5e3d92b504..fe32f853a3 100644 --- a/arbor/simulation.cpp +++ b/arbor/simulation.cpp @@ -82,8 +82,10 @@ ARB_ARBOR_API void merge_cell_events( // Merge (remaining) old and pending events. PE(communication:enqueue:merge); auto n = new_events.size(); - new_events.resize(n+pending.size()+old_events.size()); - std::merge(pending.begin(), pending.end(), old_events.begin(), old_events.end(), new_events.begin()+n); + new_events.resize(n + pending.size() + old_events.size()); + std::merge(pending.begin(), pending.end(), + old_events.begin(), old_events.end(), + new_events.begin() + (long)n); PL(); } @@ -530,13 +532,11 @@ void simulation_state::inject_events(const cse_vector& events) { simulation_builder simulation::create(recipe const & rec) { return {rec}; }; -simulation::simulation( - const recipe& rec, - context ctx, - const domain_decomposition& decomp, - arb_seed_type seed) -{ - impl_.reset(new simulation_state(rec, decomp, ctx, seed)); +simulation::simulation(const recipe& rec, + context ctx, + const domain_decomposition& decomp, + arb_seed_type seed) { + impl_ = std::make_unique(rec, decomp, ctx, seed); } void simulation::reset() { @@ -555,8 +555,7 @@ time_type simulation::run(time_type tfinal, time_type dt) { sampler_association_handle simulation::add_sampler( cell_member_predicate probeset_ids, schedule sched, - sampler_function f) -{ + sampler_function f) { return impl_->add_sampler(std::move(probeset_ids), std::move(sched), std::move(f)); } @@ -612,10 +611,10 @@ ARB_ARBOR_API epoch_function epoch_progress_bar() { t0 = t; } - double percentage = (tfinal==t0)? 1: (t-t0)/(tfinal-t0); - int val = percentage * 100; - int lpad = percentage * bar_width; - int rpad = bar_width - lpad; + auto percentage = static_cast((tfinal==t0)? 1: (t-t0)/(tfinal-t0)); + auto val = percentage * 100; + auto lpad = percentage * bar_width; + auto rpad = bar_width - lpad; printf("\r%3d%% |%.*s%*s| %12ums", val, lpad, bar_buffer.c_str(), rpad, "", (unsigned)t); if (t==tfinal) { diff --git a/arbor/threading/threading.cpp b/arbor/threading/threading.cpp index e43f13655a..43a261ee02 100644 --- a/arbor/threading/threading.cpp +++ b/arbor/threading/threading.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -137,8 +138,7 @@ task_system::task_system(int nthreads, bool bind): count_(nthreads), bind_(bind), q_(nthreads) { - if (nthreads <= 0) - throw std::runtime_error("Non-positive number of threads in thread pool"); + if (nthreads <= 0) throw std::runtime_error("Non-positive number of threads in thread pool"); for (unsigned p = 0; p=n_priority) { + assert(count_ != 0); + auto priority = ptsk.priority; + if (priority >= n_priority) { run(std::move(ptsk)); } else { - arb_assert(ptsk.priority < (int)index_.size()); - auto i = index_[ptsk.priority]++; - - for (unsigned n = 0; n != count_; n++) { - if (q_[(i + n) % count_].try_push(ptsk)) return; + auto idx = index_[priority]++; + for (unsigned n = 0; n < count_; n++) { + if (q_[(idx + n) % count_].try_push(ptsk)) return; } - q_[i % count_].push(std::move(ptsk)); + q_[idx % count_].push(std::move(ptsk)); } } diff --git a/arbor/threading/threading.hpp b/arbor/threading/threading.hpp index 35afa04e9c..6783c09c52 100644 --- a/arbor/threading/threading.hpp +++ b/arbor/threading/threading.hpp @@ -25,13 +25,13 @@ using std::condition_variable; using task = std::function; // Tasks with priority higher than max_async_task_priority will be run synchronously. -constexpr int max_async_task_priority = 1; +constexpr unsigned max_async_task_priority = 1; // Wrap task and priority; provide move/release/reset operations and reset on run() // to help ensure no wrapped task is run twice. struct priority_task { task t; - int priority = -1; + unsigned priority = 0; priority_task() = default; priority_task(task&& t, int priority): t(std::move(t)), priority(priority) {} @@ -72,7 +72,7 @@ namespace impl { class ARB_ARBOR_API notification_queue { // Number of priority levels in notification queues. - static constexpr int n_priority = max_async_task_priority+1; + static constexpr unsigned n_priority = max_async_task_priority+1; public: // Tries to acquire the lock to get a task of a requested priority. @@ -125,7 +125,7 @@ class ARB_ARBOR_API notification_queue { class ARB_ARBOR_API task_system { private: // Number of notification queues. - unsigned count_; + unsigned count_ = 1; // Attempt to bind threads? bool bind_ = false; // Worker threads. @@ -143,7 +143,7 @@ class ARB_ARBOR_API task_system { static thread_local unsigned current_task_queue_; // Number of priority levels in notification queues. - static constexpr int n_priority = max_async_task_priority+1; + static constexpr unsigned n_priority = max_async_task_priority+1; // Notification queues containing n_priority deques representing // different priority levels. diff --git a/arbor/util/partition.hpp b/arbor/util/partition.hpp index 14a50d68f0..a111b0d837 100644 --- a/arbor/util/partition.hpp +++ b/arbor/util/partition.hpp @@ -120,7 +120,7 @@ partition_range partition_view(const Seq& r) { */ struct partition_in_place_t { - constexpr partition_in_place_t() {} + constexpr partition_in_place_t() = default; }; constexpr partition_in_place_t partition_in_place; diff --git a/arborio/cableio.cpp b/arborio/cableio.cpp index 0afbad2317..a1bf7ee0cb 100644 --- a/arborio/cableio.cpp +++ b/arborio/cableio.cpp @@ -339,7 +339,7 @@ morphology make_morphology(const std::vector>& args) for (const auto& [seg, s_pid]: segs) { tree.append(s_pid, seg.prox, seg.dist, seg.tag); } - return morphology(tree); + return {tree}; } // Define cable-cell maker @@ -355,7 +355,7 @@ cable_cell make_cable_cell(const std::vector #include +#include namespace arborio { @@ -32,7 +33,7 @@ ARB_ARBORIO_API parse_label_hopefully parse_iexpr_expression(const s namespace literals { struct morph_from_string { - morph_from_string(const std::string& s): str{s} {} + morph_from_string(std::string s): str{std::move(s)} {} morph_from_string(const char* s): str{s} {} std::string str; @@ -49,7 +50,7 @@ struct morph_from_string { }; struct morph_from_label { - morph_from_label(const std::string& s): str{s} {} + morph_from_label(std::string s): str{std::move(s)} {} morph_from_label(const char* s): str{s} {} std::string str; diff --git a/arborio/neurolucida.cpp b/arborio/neurolucida.cpp index 4c8d46a1f5..213adaa591 100644 --- a/arborio/neurolucida.cpp +++ b/arborio/neurolucida.cpp @@ -95,7 +95,7 @@ parse_hopefully parse_double(asc::lexer& L) { return std::stod(t.spelling); } -#define PARSE_DOUBLE(L, X) {if (auto rval__ = parse_double(L)) X=*rval__; else return FORWARD_PARSE_ERROR(rval__.error());} +#define PARSE_DOUBLE(L, X) {if (auto rval__ = parse_double(L)) (X)=*rval__; else return FORWARD_PARSE_ERROR(rval__.error());} // Attempt to parse an integer in the range [0, 256). parse_hopefully parse_uint8(asc::lexer& L) { @@ -113,7 +113,7 @@ parse_hopefully parse_uint8(asc::lexer& L) { return static_cast(value); } -#define PARSE_UINT8(L, X) {if (auto rval__ = parse_uint8(L)) X=*rval__; else return FORWARD_PARSE_ERROR(rval__.error());} +#define PARSE_UINT8(L, X) {if (auto rval__ = parse_uint8(L)) (X)=*rval__; else return FORWARD_PARSE_ERROR(rval__.error());} // Find the matching closing parenthesis, and consume it. // Assumes that opening paren has been consumed. @@ -238,7 +238,7 @@ parse_hopefully parse_color(asc::lexer& L) { return unexpected(PARSE_ERROR("unexpected symbol in Color description \'"+t.spelling+"\'", t.loc)); } -#define PARSE_COLOR(L, X) {if (auto rval__ = parse_color(L)) X=*rval__; else return FORWARD_PARSE_ERROR(rval__.error());} +#define PARSE_COLOR(L, X) {if (auto rval__ = parse_color(L)) (X)=*rval__; else return FORWARD_PARSE_ERROR(rval__.error());} // Parse zSmear statement, which has the form: // (zSmear alpha beta) @@ -305,7 +305,7 @@ parse_hopefully parse_point(asc::lexer& L) { return p; } -#define PARSE_POINT(L, X) if (auto rval__ = parse_point(L)) X=*rval__; else return FORWARD_PARSE_ERROR(rval__.error()); +#define PARSE_POINT(L, X) if (auto rval__ = parse_point(L)) (X)=*rval__; else return FORWARD_PARSE_ERROR(rval__.error()); parse_hopefully parse_spine(asc::lexer& L) { EXPECT_TOKEN(L, tok::lt); @@ -319,7 +319,7 @@ parse_hopefully parse_spine(asc::lexer& L) { return arb::mpoint{}; } -#define PARSE_SPINE(L, X) if (auto rval__ = parse_spine(L)) X=std::move(*rval__); else return FORWARD_PARSE_ERROR(rval__.error()); +#define PARSE_SPINE(L, X) if (auto rval__ = parse_spine(L)) (X)=std::move(*rval__); else return FORWARD_PARSE_ERROR(rval__.error()); parse_hopefully parse_name(asc::lexer& L) { EXPECT_TOKEN(L, tok::lparen); @@ -340,7 +340,7 @@ parse_hopefully parse_name(asc::lexer& L) { return name; } -#define PARSE_NAME(L, X) {if (auto rval__ = parse_name(L)) X=*rval__; else return FORWARD_PARSE_ERROR(rval__.error());} +#define PARSE_NAME(L, X) {if (auto rval__ = parse_name(L)) (X)=*rval__; else return FORWARD_PARSE_ERROR(rval__.error());} struct marker_set { asc_color color; @@ -387,7 +387,7 @@ parse_hopefully parse_markers(asc::lexer& L) { return markers; } -#define PARSE_MARKER(L, X) if (auto rval__ = parse_markers(L)) X=std::move(*rval__); else return FORWARD_PARSE_ERROR(rval__.error()); +#define PARSE_MARKER(L, X) if (auto rval__ = parse_markers(L)) (X)=std::move(*rval__); else return FORWARD_PARSE_ERROR(rval__.error()); struct branch { std::vector samples; @@ -463,11 +463,8 @@ parse_hopefully parse_branch(asc::lexer& L) { } finished = true; } - else if (branch_end(t)) { - finished = true; - } - // The end of the branch followed by an explicit fork point. - else if (t.kind==tok::lparen) { + else if (branch_end(t) + || t.kind==tok::lparen) {// The end of the branch followed by an explicit fork point. finished = true; } else { @@ -636,15 +633,9 @@ ARB_ARBORIO_API arb::segment_tree parse_asc_string_raw(const char* input) { // Sections // Description t = lexer.peek(); - if (symbol_matches("Description", t)) { - lexer.next(); - parse_to_closing_paren(lexer); - } - else if (symbol_matches("ImageCoords", t)) { - lexer.next(); - parse_to_closing_paren(lexer); - } - else if (symbol_matches("Sections", t)) { + if (symbol_matches("Description", t) + || symbol_matches("ImageCoords", t) + || symbol_matches("Sections", t)) { lexer.next(); parse_to_closing_paren(lexer); } @@ -702,7 +693,7 @@ ARB_ARBORIO_API arb::segment_tree parse_asc_string_raw(const char* input) { } else { // The soma is described by a contour. - const auto ns = samples.size(); + const auto ns = static_cast(samples.size()); soma_0.x = std::accumulate(samples.begin(), samples.end(), 0., [](double a, auto& s) {return a+s.x;}) / ns; soma_0.y = std::accumulate(samples.begin(), samples.end(), 0., [](double a, auto& s) {return a+s.y;}) / ns; soma_0.z = std::accumulate(samples.begin(), samples.end(), 0., [](double a, auto& s) {return a+s.z;}) / ns; diff --git a/arborio/neuroml.cpp b/arborio/neuroml.cpp index 554b7a6db4..2b34ba3e99 100644 --- a/arborio/neuroml.cpp +++ b/arborio/neuroml.cpp @@ -42,9 +42,9 @@ struct ARB_ARBORIO_API neuroml_impl { xml_doc doc; std::string raw; - neuroml_impl() {} + neuroml_impl() = default; - explicit neuroml_impl(std::string text): raw{text} { + explicit neuroml_impl(std::string text): raw{std::move(text)} { auto res = doc.load_buffer_inplace(raw.data(), raw.size()+1); if (res.status) throw nml_parse_error{res.description()}; } @@ -63,7 +63,7 @@ std::vector neuroml::cell_ids() const { std::vector result; result.reserve(matches.size()); for (const auto& it: matches) { - result.push_back(it.attribute().as_string()); + result.emplace_back(it.attribute().as_string()); } return result; } @@ -73,7 +73,7 @@ std::vector neuroml::morphology_ids() const { std::vector result; result.reserve(matches.size()); for (const auto& it: matches) { - result.push_back(it.attribute().as_string()); + result.emplace_back(it.attribute().as_string()); } return result; } diff --git a/arborio/nml_parse_morphology.cpp b/arborio/nml_parse_morphology.cpp index 84201e49d5..b1ac16a5f6 100644 --- a/arborio/nml_parse_morphology.cpp +++ b/arborio/nml_parse_morphology.cpp @@ -19,10 +19,11 @@ #include "nml_parse_morphology.hpp" #include "xml.hpp" -using std::optional; using arb::region; +using arb::stitched_morphology; using arb::util::expected; using arb::util::unexpected; +using std::optional; using namespace std::literals; @@ -395,7 +396,7 @@ static arb::stitched_morphology construct_morphology(const neuroml_segment_tree& } } - return arb::stitched_morphology(std::move(builder)); + return {std::move(builder)}; } nml_morphology_data nml_parse_morphology_element(const xml_node& morph, @@ -424,10 +425,10 @@ nml_morphology_data nml_parse_morphology_element(const xml_node& morph, auto prox = n.select_node(q_proximal).node(); if (!prox.empty()) { - double x = get_attr(prox, "x"); - double y = get_attr(prox, "y"); - double z = get_attr(prox, "z"); - double diameter = get_attr(prox, "diameter"); + auto x = get_attr(prox, "x"); + auto y = get_attr(prox, "y"); + auto z = get_attr(prox, "z"); + auto diameter = get_attr(prox, "diameter"); if (diameter<0) throw nml_bad_segment(seg.id); seg.proximal = arb::mpoint{x, y, z, diameter/2}; } @@ -436,10 +437,10 @@ nml_morphology_data nml_parse_morphology_element(const xml_node& morph, auto dist = n.select_node(q_distal).node(); if (!dist.empty()) { - double x = get_attr(dist, "x"); - double y = get_attr(dist, "y"); - double z = get_attr(dist, "z"); - double diameter = get_attr(dist, "diameter"); + auto x = get_attr(dist, "x"); + auto y = get_attr(dist, "y"); + auto z = get_attr(dist, "z"); + auto diameter = get_attr(dist, "diameter"); if (diameter<0) throw nml_bad_segment(seg.id); seg.distal = arb::mpoint{x, y, z, diameter/2}; diff --git a/arborio/swcio.cpp b/arborio/swcio.cpp index f7ae9e79a8..6f23fcaa60 100644 --- a/arborio/swcio.cpp +++ b/arborio/swcio.cpp @@ -119,7 +119,7 @@ swc_data::swc_data(std::vector recs) : records_(sort_and_validate_swc(std::move(recs))) {}; swc_data::swc_data(std::string meta, std::vector recs) : - metadata_(meta), + metadata_(std::move(meta)), records_(sort_and_validate_swc(std::move(recs))) {}; // Parse and validate swc data @@ -152,7 +152,7 @@ ARB_ARBORIO_API swc_data parse_swc(std::istream& in) { records.push_back(r); } - return swc_data(metadata, std::move(records)); + return {metadata, std::move(records)}; } ARB_ARBORIO_API swc_data parse_swc(const std::string& text) { @@ -283,13 +283,12 @@ ARB_ARBORIO_API arb::segment_tree load_swc_neuron_raw(const swc_data& data) { // Construct a soma composed of two cylinders if is represented by a single sample. if (spherical_soma) { auto& sr = records[0]; - arb::msize_t pid = arb::mnpos; - pid = tree.append(pid, {sr.x-sr.r, sr.y, sr.z, sr.r}, - {sr.x, sr.y, sr.z, sr.r}, soma_tag); + auto pid = tree.append(arb::mnpos, {sr.x-sr.r, sr.y, sr.z, sr.r}, + {sr.x, sr.y, sr.z, sr.r}, soma_tag); // Children of the soma sample attach to the distal end of the first segment in the soma. segmap[0] = pid; - pid = tree.append(pid, {sr.x, sr.y, sr.z, sr.r}, - {sr.x+sr.r, sr.y, sr.z, sr.r}, soma_tag); + tree.append(pid, {sr.x, sr.y, sr.z, sr.r}, + {sr.x+sr.r, sr.y, sr.z, sr.r}, soma_tag); } else { segmap[0] = arb::mnpos; diff --git a/python/strprintf.hpp b/python/strprintf.hpp index 6380167726..0b0ba223ae 100644 --- a/python/strprintf.hpp +++ b/python/strprintf.hpp @@ -95,7 +95,7 @@ std::string strprintf(const char* fmt, Args&&... args) { throw std::system_error(errno, std::generic_category()); } else if ((unsigned)n(n)}; } buffer.resize(2*n); } diff --git a/sup/include/sup/ioutil.hpp b/sup/include/sup/ioutil.hpp index af05fa6cd2..bdc7fc7c68 100644 --- a/sup/include/sup/ioutil.hpp +++ b/sup/include/sup/ioutil.hpp @@ -23,14 +23,14 @@ namespace sup { template > class basic_null_streambuf: public std::basic_streambuf { private: - typedef typename std::basic_streambuf streambuf_type; + using streambuf_type = typename std::basic_streambuf; public: - typedef typename streambuf_type::char_type char_type; - typedef typename streambuf_type::int_type int_type; - typedef typename streambuf_type::pos_type pos_type; - typedef typename streambuf_type::off_type off_type; - typedef typename streambuf_type::traits_type traits_type; + using char_type = typename streambuf_type::char_type; + using int_type = typename streambuf_type::int_type; + using pos_type = typename streambuf_type::pos_type; + using off_type = typename streambuf_type::off_type; + using traits_type = typename streambuf_type::traits_type; virtual ~basic_null_streambuf() = default; @@ -55,8 +55,7 @@ class ARB_SUP_API mask_stream { operator<<(std::basic_ostream& O, const mask_stream& F) { int xindex = get_xindex(); - std::basic_streambuf* saved_streambuf = - static_cast*>(O.pword(xindex)); + auto* saved_streambuf = static_cast*>(O.pword(xindex)); if (F.mask_ && saved_streambuf) { // re-enable by restoring saved streambuf diff --git a/sup/include/sup/path.hpp b/sup/include/sup/path.hpp index 4ffd7861f2..823a68500d 100644 --- a/sup/include/sup/path.hpp +++ b/sup/include/sup/path.hpp @@ -191,9 +191,9 @@ class posix_path { posix_path parent_path() const { auto i = p_.rfind('/'); - if (i==0) return posix_path("/"); - else if (i==std::string::npos) return posix_path(); - else return posix_path(p_.substr(0, i)); + if (i==0) return {"/"}; + else if (i==std::string::npos) return {}; + else return {p_.substr(0, i)}; } bool has_parent_path() const { @@ -350,11 +350,11 @@ class filesystem_error: public std::system_error { filesystem_error(const std::string& what_arg, std::error_code ec): std::system_error(ec, what_arg) {} - filesystem_error(const std::string& what_arg, const path& p1, std::error_code ec): - std::system_error(ec, what_arg), p1_(p1) {} + filesystem_error(const std::string& what_arg, path p1, std::error_code ec): + std::system_error(ec, what_arg), p1_(std::move(p1)) {} - filesystem_error(const std::string& what_arg, const path& p1, const path& p2, std::error_code ec): - std::system_error(ec, what_arg), p1_(p1), p2_(p2) {} + filesystem_error(const std::string& what_arg, path p1, path p2, std::error_code ec): + std::system_error(ec, what_arg), p1_(std::move(p1)), p2_(std::move(p2)) {} const path& path1() const { return p1_; } const path& path2() const { return p2_; } @@ -507,8 +507,8 @@ struct directory_entry { directory_entry(const path& p, std::error_code& ec) { assign(p, ec); } // Set file type explicity: interface for directory_iterator. - directory_entry(const path& p, file_type type, std::error_code& ec): - path_(p), status_(type) + directory_entry(path p, file_type type, std::error_code& ec): + path_(std::move(p)), status_(type) { if (type==file_type::unknown) { // no information from readdir() refresh(ec); diff --git a/sup/path.cpp b/sup/path.cpp index d12946ee3b..62a4fa9fa8 100644 --- a/sup/path.cpp +++ b/sup/path.cpp @@ -16,7 +16,7 @@ namespace impl { if (!r) { // Success: ec.clear(); - perms p = static_cast(st.st_mode&07777); + auto p = static_cast(st.st_mode&07777); switch (st.st_mode&S_IFMT) { case S_IFSOCK: return file_status{file_type::socket, p}; diff --git a/test/unit/test_filter.cpp b/test/unit/test_filter.cpp index 54238a6b10..c822788f3c 100644 --- a/test/unit/test_filter.cpp +++ b/test/unit/test_filter.cpp @@ -51,13 +51,13 @@ TEST(filter, const_sentinel) { } TEST(filter, modify_regular) { - int nums[] = {1, -2, 3, -4, -5}; + std::array nums{1, -2, 3, -4, -5}; for (auto& n: filter(nums, [](int i) { return i<0; })) { n *= n; } - int check[] = {1, 4, 3, 16, 25}; + std::array check = {1, 4, 3, 16, 25}; for (unsigned i = 0; i<5; ++i) { EXPECT_EQ(check[i], nums[i]); } From 83969c68537296df606dc9712ae5f24929aa7c85 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Thu, 4 May 2023 16:36:11 +0200 Subject: [PATCH 02/17] Fix all clang-tidy warning in everything except: ext, python, modcc, example, test. --- arbor/affinity.hpp | 2 +- arbor/arbexcept.cpp | 4 +- arbor/backends/multicore/shared_state.cpp | 9 ++- .../backends/multicore/threshold_watcher.hpp | 4 +- arbor/backends/shared_state_base.hpp | 4 +- arbor/benchmark_cell_group.cpp | 4 +- arbor/cable_cell.cpp | 2 +- arbor/communication/communicator.cpp | 3 +- arbor/communication/dry_run_context.cpp | 6 +- arbor/cv_policy.cpp | 4 +- arbor/distributed_context.hpp | 4 +- arbor/domain_decomposition.cpp | 4 +- arbor/fvm_lowered_cell.hpp | 2 +- arbor/fvm_lowered_cell_impl.hpp | 10 +-- arbor/hardware/power.cpp | 2 +- arbor/include/arbor/arbexcept.hpp | 2 +- arbor/include/arbor/morph/locset.hpp | 8 +-- arbor/include/arbor/morph/mprovider.hpp | 2 +- arbor/include/arbor/morph/region.hpp | 8 +-- arbor/include/arbor/profile/clock.hpp | 2 +- arbor/include/arbor/recipe.hpp | 2 +- arbor/include/arbor/s_expr.hpp | 6 +- arbor/include/arbor/sampling.hpp | 2 +- arbor/include/arbor/schedule.hpp | 26 +++---- arbor/include/arbor/simd/neon.hpp | 2 +- arbor/include/arbor/simd/simd.hpp | 18 ++--- arbor/include/arbor/simulation.hpp | 2 +- arbor/include/arbor/util/compat.hpp | 2 +- arbor/include/arbor/util/expected.hpp | 32 ++++++--- arbor/io/locked_ostream.cpp | 20 +++--- arbor/io/locked_ostream.hpp | 2 +- arbor/io/trace.hpp | 2 +- arbor/label_resolution.hpp | 4 +- arbor/lif_cell_group.cpp | 6 +- arbor/mechcat.cpp | 3 +- arbor/memory/allocator.hpp | 4 +- arbor/memory/array.hpp | 2 +- arbor/memory/array_view.hpp | 10 +-- arbor/memory/definitions.hpp | 18 ++--- arbor/memory/device_coordinator.hpp | 9 +-- arbor/memory/gpu_wrappers.cpp | 28 +++----- arbor/memory/host_coordinator.hpp | 8 +-- arbor/morph/embed_pwlin.cpp | 5 +- arbor/morph/locset.cpp | 12 ++-- arbor/morph/morphexcept.cpp | 4 +- arbor/morph/mprovider.cpp | 5 +- arbor/morph/place_pwlin.cpp | 67 ++++++++++--------- arbor/morph/region.cpp | 6 +- arbor/partition_load_balance.cpp | 2 +- arbor/profile/clock.cpp | 2 +- arbor/profile/meter_manager.cpp | 5 +- arbor/profile/profiler.cpp | 5 +- arbor/s_expr.cpp | 11 ++- arbor/spike_source_cell_group.cpp | 2 +- arbor/symmetric_recipe.cpp | 6 +- arbor/timestep_range.hpp | 2 +- arbor/util/cbrng.hpp | 4 +- arbor/util/padded_alloc.hpp | 2 +- arbor/util/piecewise.hpp | 1 + arbor/util/sentinel.hpp | 4 +- arbor/util/strprintf.hpp | 4 +- arbor/util/unwind.cpp | 17 +++-- arborenv/arbenvexcept.cpp | 2 +- arborenv/read_envvar.cpp | 6 +- arborio/asc_lexer.cpp | 12 ++-- arborio/cableio.cpp | 4 ++ arborio/neurolucida.cpp | 9 ++- arborio/nml_parse_morphology.cpp | 15 ++--- arborio/swcio.cpp | 5 +- lmorpho/lmorpho.cpp | 2 +- python/strprintf.hpp | 2 +- sup/include/sup/ioutil.hpp | 6 +- sup/include/sup/path.hpp | 16 ++--- sup/include/sup/strsub.hpp | 2 +- sup/json_meter.cpp | 4 +- sup/path.cpp | 7 +- 76 files changed, 294 insertions(+), 258 deletions(-) diff --git a/arbor/affinity.hpp b/arbor/affinity.hpp index 99ccf91263..063540bdf3 100644 --- a/arbor/affinity.hpp +++ b/arbor/affinity.hpp @@ -44,7 +44,7 @@ void set_affinity(int index, int count, affinity_kind kind) { hwloc(hwloc_topology_load(topology), "Topo load"); // Fetch our current restrictions and apply them to our topology hwloc_cpuset_t cpus = hwloc_bitmap_alloc(); - hwloc(cpus == NULL, "Bitmap allocation"); + hwloc(cpus == nullptr, "Bitmap allocation"); auto bitmap_guard = util::on_scope_exit([&] { hwloc_bitmap_free(cpus); }); hwloc(hwloc_get_cpubind(topology, cpus, HWLOC_CPUBIND_PROCESS), "Get cpuset."); hwloc(hwloc_topology_restrict(topology, cpus, 0), "Topo restrict."); diff --git a/arbor/arbexcept.cpp b/arbor/arbexcept.cpp index 5d01b5bdf2..f4db0cc15c 100644 --- a/arbor/arbexcept.cpp +++ b/arbor/arbexcept.cpp @@ -163,8 +163,8 @@ bad_catalogue_error::bad_catalogue_error(const std::string& msg) : arbor_exception(pprintf("Error while opening catalogue '{}'", msg)) {} -bad_catalogue_error::bad_catalogue_error(const std::string& msg, const std::any& pe) - : arbor_exception(pprintf("Error while opening catalogue '{}'", msg)), platform_error(pe) +bad_catalogue_error::bad_catalogue_error(const std::string& msg, std::any pe) + : arbor_exception(pprintf("Error while opening catalogue '{}'", msg)), platform_error(std::move(pe)) {} unsupported_abi_error::unsupported_abi_error(size_t v): diff --git a/arbor/backends/multicore/shared_state.cpp b/arbor/backends/multicore/shared_state.cpp index d7477282c7..54b3dc5160 100644 --- a/arbor/backends/multicore/shared_state.cpp +++ b/arbor/backends/multicore/shared_state.cpp @@ -31,7 +31,6 @@ namespace arb { namespace multicore { -using util::make_range; using util::make_span; using util::ptr_by_key; using util::value_by_key; @@ -182,7 +181,7 @@ void istim_state::add_current(const arb_value_type time, array& current_density) J = math::lerp(J, J1, u); } - if (frequency_[i]) { + if (0 != frequency_[i]) { J *= std::sin(two_pi*frequency_[i]*time + phase_[i]); } @@ -215,7 +214,7 @@ shared_state::shared_state(task_system_handle, // ignored in mc backend init_voltage(init_membrane_potential.begin(), init_membrane_potential.end(), pad(alignment)), temperature_degC(n_cv_, pad(alignment)), diam_um(diam.begin(), diam.end(), pad(alignment)), - time_since_spike(n_cell*n_detector, pad(alignment)), + time_since_spike(n_cell*static_cast(n_detector), pad(alignment)), src_to_spike(src_to_spike_.begin(), src_to_spike_.end(), pad(alignment)), cbprng_seed(cbprng_seed_), watcher{n_cv_, @@ -406,7 +405,7 @@ void shared_state::instantiate(arb::mechanism& m, m.ppack_.temperature_degC = temperature_degC.data(); m.ppack_.diam_um = diam_um.data(); m.ppack_.time_since_spike = time_since_spike.data(); - m.ppack_.n_detectors = n_detector; + m.ppack_.n_detectors = static_cast(n_detector); m.ppack_.events = {}; bool mult_in_place = !pos_data.multiplicity.empty(); @@ -429,7 +428,7 @@ void shared_state::instantiate(arb::mechanism& m, if (!oion) throw arbor_internal_error(util::pprintf("multicore/mechanism: mechanism holds ion '{}' with no corresponding shared state", ion)); auto& ion_state = m.ppack_.ion_states[idx]; - ion_state = {0}; + ion_state = {nullptr}; ion_state.current_density = oion->iX_.data(); ion_state.reversal_potential = oion->eX_.data(); ion_state.internal_concentration = oion->Xi_.data(); diff --git a/arbor/backends/multicore/threshold_watcher.hpp b/arbor/backends/multicore/threshold_watcher.hpp index b3419cdbb8..c0cbaaa9dd 100644 --- a/arbor/backends/multicore/threshold_watcher.hpp +++ b/arbor/backends/multicore/threshold_watcher.hpp @@ -14,13 +14,13 @@ namespace multicore { class threshold_watcher { public: threshold_watcher() = default; - threshold_watcher(const execution_context& ctx) {} + threshold_watcher(const execution_context&) {} threshold_watcher(const arb_size_type num_cv, const arb_index_type* src_to_spike, const std::vector& cv_index, const std::vector& thresholds, - const execution_context& context): + const execution_context&): src_to_spike_(src_to_spike), n_detectors_(cv_index.size()), cv_index_(cv_index), diff --git a/arbor/backends/shared_state_base.hpp b/arbor/backends/shared_state_base.hpp index dde9e29e45..4017f0d5a4 100644 --- a/arbor/backends/shared_state_base.hpp +++ b/arbor/backends/shared_state_base.hpp @@ -3,6 +3,8 @@ #include #include +#include "timestep_range.hpp" + #include "backends/event.hpp" #include "backends/common_types.hpp" #include "fvm_layout.hpp" @@ -28,7 +30,7 @@ struct shared_state_base { void begin_epoch(const std::vector>>& staged_events_per_mech_id, const std::vector>& samples, - const timestep_range& dts) { + const timestep_range&) { auto d = static_cast(this); // events auto& storage = d->storage; diff --git a/arbor/benchmark_cell_group.cpp b/arbor/benchmark_cell_group.cpp index f941836c3d..512b59d897 100644 --- a/arbor/benchmark_cell_group.cpp +++ b/arbor/benchmark_cell_group.cpp @@ -55,8 +55,8 @@ cell_kind benchmark_cell_group::get_cell_kind() const { } void benchmark_cell_group::advance(epoch ep, - time_type dt, - const event_lane_subrange& event_lanes) + time_type /*dt*/, + const event_lane_subrange& /*event_lanes*/) { using std::chrono::high_resolution_clock; using duration_type = std::chrono::duration; diff --git a/arbor/cable_cell.cpp b/arbor/cable_cell.cpp index 07acbffcea..04a0c7a02a 100644 --- a/arbor/cable_cell.cpp +++ b/arbor/cable_cell.cpp @@ -213,7 +213,7 @@ struct cable_cell_impl { using impl_ptr = std::unique_ptr; impl_ptr make_impl(cable_cell_impl* c) { - return impl_ptr(c, [](cable_cell_impl* p){delete p;}); + return {c, [](cable_cell_impl* p){ delete p; }}; } void cable_cell_impl::init(const decor& d) { diff --git a/arbor/communication/communicator.cpp b/arbor/communication/communicator.cpp index 0fa2798e70..2b02ee92c1 100644 --- a/arbor/communication/communicator.cpp +++ b/arbor/communication/communicator.cpp @@ -209,7 +209,8 @@ communicator::exchange(std::vector local_spikes) { if (remote_spike_filter_) { local_spikes.erase(std::remove_if(local_spikes.begin(), local_spikes.end(), - [this] (const auto& s) { return !remote_spike_filter_(s); })); + [this] (const auto& s) { return !remote_spike_filter_(s); }), + local_spikes.end()); } auto remote_spikes = distributed_->remote_gather_spikes(local_spikes); PL(); diff --git a/arbor/communication/dry_run_context.cpp b/arbor/communication/dry_run_context.cpp index be36fd6ff3..2019c2a6ab 100644 --- a/arbor/communication/dry_run_context.cpp +++ b/arbor/communication/dry_run_context.cpp @@ -16,14 +16,14 @@ struct dry_run_context_impl { explicit dry_run_context_impl(unsigned num_ranks, unsigned num_cells_per_tile): num_ranks_(num_ranks), num_cells_per_tile_(num_cells_per_tile) {}; std::vector - remote_gather_spikes(const std::vector& local_spikes) const { + remote_gather_spikes(const std::vector& /*local_spikes*/) const { return {}; } gathered_vector gather_spikes(const std::vector& local_spikes) const { using count_type = typename gathered_vector::count_type; - count_type local_size = local_spikes.size(); + auto local_size = local_spikes.size(); std::vector gathered_spikes; gathered_spikes.reserve(local_size*num_ranks_); @@ -51,7 +51,7 @@ struct dry_run_context_impl { gather_gids(const std::vector& local_gids) const { using count_type = typename gathered_vector::count_type; - count_type local_size = local_gids.size(); + auto local_size = local_gids.size(); std::vector gathered_gids; gathered_gids.reserve(local_size*num_ranks_); diff --git a/arbor/cv_policy.cpp b/arbor/cv_policy.cpp index 04d9eeaeb1..25a163f98f 100644 --- a/arbor/cv_policy.cpp +++ b/arbor/cv_policy.cpp @@ -14,9 +14,11 @@ namespace arb { -static auto unique_sum = [](auto&&... lss) { +namespace { +auto unique_sum = [](auto&&... lss) { return ls::support(sum(std::forward(lss)...)); }; +} // Combinators: // cv_policy_plus_ represents the result of operator+, diff --git a/arbor/distributed_context.hpp b/arbor/distributed_context.hpp index 7299929d05..3196ebaeae 100644 --- a/arbor/distributed_context.hpp +++ b/arbor/distributed_context.hpp @@ -52,7 +52,7 @@ class distributed_context { // default constructor uses a local context: see below. distributed_context(); - template + template >> distributed_context(Impl&& impl): impl_(new wrap(std::forward(impl))) {} @@ -204,7 +204,7 @@ struct local_context { ); } std::vector - remote_gather_spikes(const std::vector& local_spikes) const { + remote_gather_spikes(const std::vector& /*local_spikes*/) const { return {}; } gathered_vector diff --git a/arbor/domain_decomposition.cpp b/arbor/domain_decomposition.cpp index aa22082120..bc4f315253 100644 --- a/arbor/domain_decomposition.cpp +++ b/arbor/domain_decomposition.cpp @@ -19,7 +19,7 @@ domain_decomposition::domain_decomposition( const std::vector& groups) { struct partition_gid_domain { - partition_gid_domain(const gathered_vector& divs, unsigned domains) { + partition_gid_domain(const gathered_vector& divs) { auto rank_part = util::partition_view(divs.partition()); for (auto rank: count_along(rank_part)) { for (auto gid: util::subrange_view(divs.values(), rank_part[rank])) { @@ -81,7 +81,7 @@ domain_decomposition::domain_decomposition( num_local_cells_ = num_local_cells; num_global_cells_ = num_global_cells; groups_ = groups; - gid_domain_ = partition_gid_domain(global_gids, num_domains); + gid_domain_ = partition_gid_domain(global_gids); } int domain_decomposition::gid_domain(cell_gid_type gid) const { diff --git a/arbor/fvm_lowered_cell.hpp b/arbor/fvm_lowered_cell.hpp index 899f073f43..602ac7e99d 100644 --- a/arbor/fvm_lowered_cell.hpp +++ b/arbor/fvm_lowered_cell.hpp @@ -224,7 +224,7 @@ struct fvm_lowered_cell { virtual arb_value_type time() const = 0; - virtual ~fvm_lowered_cell() {} + virtual ~fvm_lowered_cell() = default; }; using fvm_lowered_cell_ptr = std::unique_ptr; diff --git a/arbor/fvm_lowered_cell_impl.hpp b/arbor/fvm_lowered_cell_impl.hpp index 69ca5b1554..00d41000cc 100644 --- a/arbor/fvm_lowered_cell_impl.hpp +++ b/arbor/fvm_lowered_cell_impl.hpp @@ -47,7 +47,7 @@ class fvm_lowered_cell_impl: public fvm_lowered_cell { using size_type = arb_size_type; fvm_lowered_cell_impl(execution_context ctx, arb_seed_type seed = 0): - context_(ctx), + context_(std::move(ctx)), seed_{seed} {}; @@ -713,7 +713,7 @@ void resolve_probe(const cable_probe_membrane_voltage& p, probe_resolution_data< } template -void resolve_probe(const cable_probe_membrane_voltage_cell& p, probe_resolution_data& R) { +void resolve_probe(const cable_probe_membrane_voltage_cell& /*p*/, probe_resolution_data& R) { fvm_probe_multi r; mcable_list cables; @@ -762,7 +762,7 @@ void resolve_probe(const cable_probe_total_ion_current_density& p, probe_resolut } template -void resolve_probe(const cable_probe_total_ion_current_cell& p, probe_resolution_data& R) { +void resolve_probe(const cable_probe_total_ion_current_cell& /*p*/, probe_resolution_data& R) { fvm_probe_interpolated_multi r; std::vector stim_handles; @@ -789,7 +789,7 @@ void resolve_probe(const cable_probe_total_ion_current_cell& p, probe_resolution } template -void resolve_probe(const cable_probe_total_current_cell& p, probe_resolution_data& R) { +void resolve_probe(const cable_probe_total_current_cell& /*p*/, probe_resolution_data& R) { fvm_probe_membrane_currents r; auto cell_cv_ival = R.D.geometry.cell_cv_interval(R.cell_idx); @@ -829,7 +829,7 @@ void resolve_probe(const cable_probe_total_current_cell& p, probe_resolution_dat } template -void resolve_probe(const cable_probe_stimulus_current_cell& p, probe_resolution_data& R) { +void resolve_probe(const cable_probe_stimulus_current_cell& /*p*/, probe_resolution_data& R) { fvm_probe_weighted_multi r; const auto& stim_cvs = R.M.stimuli.cv_unique; diff --git a/arbor/hardware/power.cpp b/arbor/hardware/power.cpp index 7ca8df68ff..b507c42af5 100644 --- a/arbor/hardware/power.cpp +++ b/arbor/hardware/power.cpp @@ -14,7 +14,7 @@ bool has_energy_measurement() { } energy_size_type energy() { - energy_size_type result = energy_size_type(-1); + auto result = energy_size_type(-1); std::ifstream fid(CRAY_PM_COUNTER_ENERGY); if (fid) { diff --git a/arbor/include/arbor/arbexcept.hpp b/arbor/include/arbor/arbexcept.hpp index 1ec471d101..e61f348e46 100644 --- a/arbor/include/arbor/arbexcept.hpp +++ b/arbor/include/arbor/arbexcept.hpp @@ -179,7 +179,7 @@ struct ARB_SYMBOL_VISIBLE file_not_found_error: arbor_exception { // struct ARB_SYMBOL_VISIBLE bad_catalogue_error: arbor_exception { bad_catalogue_error(const std::string&); - bad_catalogue_error(const std::string&, const std::any&); + bad_catalogue_error(const std::string&, std::any); std::any platform_error; }; diff --git a/arbor/include/arbor/morph/locset.hpp b/arbor/include/arbor/morph/locset.hpp index ec127aea16..536fde2173 100644 --- a/arbor/include/arbor/morph/locset.hpp +++ b/arbor/include/arbor/morph/locset.hpp @@ -83,7 +83,7 @@ class ARB_SYMBOL_VISIBLE locset { private: struct interface { - virtual ~interface() {} + virtual ~interface() = default; virtual std::unique_ptr clone() = 0; virtual std::ostream& print(std::ostream&) = 0; virtual mlocation_list thingify(const mprovider&) = 0; @@ -96,15 +96,15 @@ class ARB_SYMBOL_VISIBLE locset { explicit wrap(const Impl& impl): wrapped(impl) {} explicit wrap(Impl&& impl): wrapped(std::move(impl)) {} - virtual std::unique_ptr clone() override { + std::unique_ptr clone() override { return std::unique_ptr(new wrap(wrapped)); } - virtual mlocation_list thingify(const mprovider& m) override { + mlocation_list thingify(const mprovider& m) override { return thingify_(wrapped, m); } - virtual std::ostream& print(std::ostream& o) override { + std::ostream& print(std::ostream& o) override { return o << wrapped; } diff --git a/arbor/include/arbor/morph/mprovider.hpp b/arbor/include/arbor/morph/mprovider.hpp index 40196c715a..fbd8bcfc40 100644 --- a/arbor/include/arbor/morph/mprovider.hpp +++ b/arbor/include/arbor/morph/mprovider.hpp @@ -30,7 +30,7 @@ struct ARB_ARBOR_API mprovider { private: mprovider(arb::morphology m, const label_dict* ldptr): - morphology_(m), embedding_(m), label_dict_ptr(ldptr) { init(); } + morphology_(std::move(m)), embedding_(morphology_), label_dict_ptr(ldptr) { init(); } arb::morphology morphology_; concrete_embedding embedding_; diff --git a/arbor/include/arbor/morph/region.hpp b/arbor/include/arbor/morph/region.hpp index a2825abf4d..03807b7f69 100644 --- a/arbor/include/arbor/morph/region.hpp +++ b/arbor/include/arbor/morph/region.hpp @@ -87,7 +87,7 @@ class ARB_SYMBOL_VISIBLE region { private: struct interface { - virtual ~interface() {} + virtual ~interface() = default; virtual std::unique_ptr clone() = 0; virtual std::ostream& print(std::ostream&) = 0; virtual mextent thingify(const mprovider&) = 0; @@ -100,15 +100,15 @@ class ARB_SYMBOL_VISIBLE region { explicit wrap(const Impl& impl): wrapped(impl) {} explicit wrap(Impl&& impl): wrapped(std::move(impl)) {} - virtual std::unique_ptr clone() override { + std::unique_ptr clone() override { return std::make_unique>(wrapped); } - virtual mextent thingify(const mprovider& m) override { + mextent thingify(const mprovider& m) override { return thingify_(wrapped, m); } - virtual std::ostream& print(std::ostream& o) override { + std::ostream& print(std::ostream& o) override { return o << wrapped; } diff --git a/arbor/include/arbor/profile/clock.hpp b/arbor/include/arbor/profile/clock.hpp index f7183673ac..d9cd72a0fe 100644 --- a/arbor/include/arbor/profile/clock.hpp +++ b/arbor/include/arbor/profile/clock.hpp @@ -2,7 +2,7 @@ #include -typedef unsigned long long tick_type; +using tick_type = unsigned long long; // Assuming POSIX monotonic clock is available; add // feature test if we need to fall back to generic or diff --git a/arbor/include/arbor/recipe.hpp b/arbor/include/arbor/recipe.hpp index 61a03428ba..e5cad087b8 100644 --- a/arbor/include/arbor/recipe.hpp +++ b/arbor/include/arbor/recipe.hpp @@ -86,7 +86,7 @@ struct ARB_ARBOR_API has_external_synapses { }; struct ARB_ARBOR_API has_probes { - virtual std::vector get_probes(cell_gid_type gid) const { + virtual std::vector get_probes(cell_gid_type) const { return {}; } virtual ~has_probes() = default; diff --git a/arbor/include/arbor/s_expr.hpp b/arbor/include/arbor/s_expr.hpp index 85f62d3eb9..be3b86473a 100644 --- a/arbor/include/arbor/s_expr.hpp +++ b/arbor/include/arbor/s_expr.hpp @@ -55,7 +55,7 @@ struct symbol { operator std::string() const { return str; } }; -inline symbol operator"" _symbol(const char* chars, size_t size) { +inline symbol operator"" _symbol(const char* chars, size_t /*size*/) { return {chars}; } @@ -131,7 +131,7 @@ struct ARB_ARBOR_API s_expr { if (finished()) inner_ = nullptr; } - s_expr_iterator_impl(const sentinel& e): + s_expr_iterator_impl(const sentinel& /*e*/): inner_(nullptr) {} @@ -167,7 +167,7 @@ struct ARB_ARBOR_API s_expr { bool operator!=(const s_expr_iterator_impl& other) const { return !(*this==other); } - bool operator==(const sentinel& other) const { + bool operator==(const sentinel& /*other*/) const { return !inner_; } bool operator!=(const sentinel& other) const { diff --git a/arbor/include/arbor/sampling.hpp b/arbor/include/arbor/sampling.hpp index 2204faf059..56c498f537 100644 --- a/arbor/include/arbor/sampling.hpp +++ b/arbor/include/arbor/sampling.hpp @@ -10,7 +10,7 @@ namespace arb { using cell_member_predicate = std::function; -static cell_member_predicate all_probes = [](cell_member_type pid) { return true; }; +static cell_member_predicate all_probes = [](cell_member_type) { return true; }; inline cell_member_predicate one_probe(cell_member_type pid) { return [pid](cell_member_type x) { return pid==x; }; diff --git a/arbor/include/arbor/schedule.hpp b/arbor/include/arbor/schedule.hpp index 2f3562f773..268d72e95c 100644 --- a/arbor/include/arbor/schedule.hpp +++ b/arbor/include/arbor/schedule.hpp @@ -38,7 +38,7 @@ class schedule { template , schedule>>> explicit schedule(Impl&& impl): - impl_(new wrap(std::move(impl))) {} + impl_(new wrap(std::forward(impl))) {} schedule(schedule&& other) = default; schedule& operator=(schedule&& other) = default; @@ -62,7 +62,7 @@ class schedule { virtual time_event_span events(time_type t0, time_type t1) = 0; virtual void reset() = 0; virtual std::unique_ptr clone() = 0; - virtual ~interface() {} + virtual ~interface() = default; }; using iface_ptr = std::unique_ptr ; @@ -74,19 +74,19 @@ class schedule { explicit wrap(const Impl& impl): wrapped(impl) {} explicit wrap(Impl&& impl): wrapped(std::move(impl)) {} - virtual time_event_span events(time_type t0, time_type t1) { + time_event_span events(time_type t0, time_type t1) override { return wrapped.events(t0, t1); } - virtual void reset() { + void reset() override { wrapped.reset(); } - virtual iface_ptr clone() { + iface_ptr clone() override { return std::make_unique>(wrapped); } - - Impl wrapped; + private: + Impl wrapped; }; }; @@ -95,7 +95,7 @@ class schedule { class empty_schedule { public: void reset() {} - time_event_span events(time_type t0, time_type t1) { + time_event_span events(time_type, time_type) { static time_type no_time; return {&no_time, &no_time}; } @@ -144,9 +144,7 @@ class ARB_ARBOR_API explicit_schedule_impl { explicit_schedule_impl(explicit_schedule_impl&&) = default; template - explicit explicit_schedule_impl(const Seq& seq): - start_index_(0) - { + explicit explicit_schedule_impl(const Seq& seq) { using std::begin; using std::end; @@ -154,14 +152,12 @@ class ARB_ARBOR_API explicit_schedule_impl { arb_assert(std::is_sorted(times_.begin(), times_.end())); } - void reset() { - start_index_ = 0; - } + void reset() { start_index_ = 0; } time_event_span events(time_type t0, time_type t1); private: - std::ptrdiff_t start_index_; + std::ptrdiff_t start_index_= 0; std::vector times_; }; diff --git a/arbor/include/arbor/simd/neon.hpp b/arbor/include/arbor/simd/neon.hpp index 6743452f9c..d5efa73450 100644 --- a/arbor/include/arbor/simd/neon.hpp +++ b/arbor/include/arbor/simd/neon.hpp @@ -555,7 +555,7 @@ struct neon_double2 : implbase { // coefficients // a0, ..., an by a0+x·(a1+x·(a2+...+x·an)...). - static inline float64x2_t horner(float64x2_t x, double a0) { + static inline float64x2_t horner(float64x2_t, double a0) { return broadcast(a0); } diff --git a/arbor/include/arbor/simd/simd.hpp b/arbor/include/arbor/simd/simd.hpp index 934c5aee43..3f924b0966 100644 --- a/arbor/include/arbor/simd/simd.hpp +++ b/arbor/include/arbor/simd/simd.hpp @@ -151,17 +151,17 @@ namespace detail { }; template - static void indirect_copy_to(const simd_mask_impl& s, V* p, unsigned width) { + static void indirect_copy_to(const simd_mask_impl& s, V* p, unsigned) { Impl::mask_copy_to(s.value_, p); } template - static void indirect_copy_to(const simd_impl& s, V* p, unsigned width) { + static void indirect_copy_to(const simd_impl& s, V* p, unsigned) { Impl::copy_to(s.value_, p); } template - static void indirect_copy_to(const simd_impl& data, const simd_mask_impl& mask, V* p, unsigned width) { + static void indirect_copy_to(const simd_impl& data, const simd_mask_impl& mask, V* p, unsigned) { Impl::copy_to_masked(data.value_, p, mask.value_); } @@ -230,12 +230,12 @@ namespace detail { }; template - static void indirect_indexed_copy_to(const simd_impl& s, V* p, const simd_impl& index, unsigned width) { + static void indirect_indexed_copy_to(const simd_impl& s, V* p, const simd_impl& index, unsigned) { Impl::scatter(tag{}, s.value_, p, index.value_); } template - static void indirect_indexed_copy_to(const simd_impl& data, const simd_mask_impl& mask, V* p, const simd_impl& index, unsigned width) { + static void indirect_indexed_copy_to(const simd_impl& data, const simd_mask_impl& mask, V* p, const simd_impl& index, unsigned) { Impl::scatter(tag{}, data.value_, p, index.value_, mask.value_); } @@ -334,12 +334,12 @@ namespace detail { } template - static void where_copy_to(const simd_mask_impl& mask, simd_impl& f, const V* t, unsigned width) { + static void where_copy_to(const simd_mask_impl& mask, simd_impl& f, const V* t, unsigned) { f.value_ = Impl::ifelse(mask.value_, Impl::copy_from_masked(t, mask.value_), f.value_); } template - static void where_copy_to(const simd_mask_impl& mask, simd_impl& f, const V* p, const simd_impl& index, unsigned width) { + static void where_copy_to(const simd_mask_impl& mask, simd_impl& f, const V* p, const simd_impl& index, unsigned) { simd_impl temp = Impl::broadcast(0); temp.value_ = Impl::gather(tag{}, temp.value_, p, index.value_, mask.value_); f.value_ = Impl::ifelse(mask.value_, temp.value_, f.value_); @@ -984,12 +984,12 @@ To simd_cast(const From& s) { } template ::value, int> = 0> -inline constexpr int width(const S a = S{}) { +inline constexpr int width(const S = S{}) { return S::width; }; template ::value, int> = 0> -inline constexpr unsigned min_align(const S a = S{}) { +inline constexpr unsigned min_align(const S = S{}) { return S::min_align; }; diff --git a/arbor/include/arbor/simulation.hpp b/arbor/include/arbor/simulation.hpp index 65724970fd..ba222fb431 100644 --- a/arbor/include/arbor/simulation.hpp +++ b/arbor/include/arbor/simulation.hpp @@ -38,7 +38,7 @@ class ARB_ARBOR_API simulation { std::function balancer = [](auto& r, auto c) { return partition_load_balance(r, c); }, arb_seed_type seed = 0): - simulation(rec, ctx, balancer(rec, ctx)) {} + simulation(rec, ctx, balancer(rec, ctx), seed) {} simulation(simulation const&) = delete; simulation(simulation&&); diff --git a/arbor/include/arbor/util/compat.hpp b/arbor/include/arbor/util/compat.hpp index 531f7f73a3..edfb09b3e5 100644 --- a/arbor/include/arbor/util/compat.hpp +++ b/arbor/include/arbor/util/compat.hpp @@ -9,7 +9,7 @@ namespace compat { -constexpr bool using_intel_compiler(int major=0, int minor=0, int patchlevel=0) { +constexpr bool using_intel_compiler(int=0, int=0, int=0) { #if defined(__INTEL_COMPILER) return __INTEL_COMPILER >= major*100 + minor && __INTEL_COMPILER_UPDATE >= patchlevel; diff --git a/arbor/include/arbor/util/expected.hpp b/arbor/include/arbor/util/expected.hpp index 836b072db1..9b3f67dec6 100644 --- a/arbor/include/arbor/util/expected.hpp +++ b/arbor/include/arbor/util/expected.hpp @@ -14,6 +14,7 @@ #include #include +#include #include namespace arb { @@ -50,7 +51,7 @@ struct bad_expected_access: std::exception { template struct bad_expected_access: public bad_expected_access { - explicit bad_expected_access(E error): error_(error) {} + explicit bad_expected_access(E error): error_(std::move(error)) {} E& error() & { return error_; } const E& error() const& { return error_; } @@ -106,15 +107,15 @@ struct unexpected { // Assignment operators. - unexpected& operator=(const unexpected& u) { return value_ = u.value_, *this; } + unexpected& operator=(const unexpected& u) { value_ = u.value_; return *this; } - unexpected& operator=(unexpected&& u) { return value_ = std::move(u.value_), *this; } + unexpected& operator=(unexpected&& u) { value_ = std::move(u.value_); return *this; } template - unexpected& operator=(const unexpected& u) { return value_ = u.value_, *this; } + unexpected& operator=(const unexpected& u) { value_ = u.value_; return *this; } template - unexpected& operator=(unexpected&& u) { return value_ = std::move(u.value_), *this; } + unexpected& operator=(unexpected&& u) { value_ = std::move(u.value_); return *this; } // Access. @@ -498,11 +499,24 @@ struct expected { if (!has_value()) throw bad_expected_access(error()); } - const E& error() const& { return data_->value(); } - E& error() & { return data_->value(); } + const E& error() const& { + if (!data_.has_value()) throw arbor_internal_error("Invalid state of expected: neither error nor value"); + return data_->value(); + } + E& error() & { + if (!data_.has_value()) throw arbor_internal_error("Invalid state of expected: neither error nor value"); + return data_->value(); + } - const E&& error() const&& { return std::move(data_->value()); } - E&& error() && { return std::move(data_->value()); } + const E&& error() const&& { + if (!data_.has_value()) throw arbor_internal_error("Invalid state of expected: neither error nor value"); + return std::move(data_->value()); + } + + E&& error() && { + if (!data_.has_value()) throw arbor_internal_error("Invalid state of expected: neither error nor value"); + return std::move(data_->value()); + } private: data_type data_; diff --git a/arbor/io/locked_ostream.cpp b/arbor/io/locked_ostream.cpp index 1aa8552170..f4948e395e 100644 --- a/arbor/io/locked_ostream.cpp +++ b/arbor/io/locked_ostream.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -11,34 +12,36 @@ namespace io { using tbl_type = std::unordered_map>; -static tbl_type& g_mex_tbl() { +namespace { + +tbl_type& g_mex_tbl() { static tbl_type tbl; return tbl; } -static std::mutex& g_mex_tbl_mex() { +std::mutex& g_mex_tbl_mex() { static std::mutex mex; return mex; } -static std::shared_ptr register_sbuf(std::streambuf* b) { +std::shared_ptr register_sbuf(std::streambuf* b) { if (b) { std::lock_guard lock(g_mex_tbl_mex()); auto& wptr = g_mex_tbl()[b]; auto mex = wptr.lock(); if (!mex) { - mex = std::shared_ptr(new std::mutex); + mex = std::make_shared(); wptr = mex; } return mex; } else { - return std::shared_ptr(); + return std::make_shared(); } } -static void deregister_sbuf(std::streambuf* b) { +void deregister_sbuf(std::streambuf* b) { if (b) { std::lock_guard lock(g_mex_tbl_mex()); @@ -48,6 +51,7 @@ static void deregister_sbuf(std::streambuf* b) { } } } +} locked_ostream::locked_ostream(std::streambuf *b): std::ostream(b), @@ -56,10 +60,10 @@ locked_ostream::locked_ostream(std::streambuf *b): locked_ostream::locked_ostream(locked_ostream&& other): - std::ostream(std::move(other)), + std::ostream(std::move(other)), // This moves other mex(std::move(other.mex)) { - set_rdbuf(other.rdbuf()); + set_rdbuf(other.rdbuf()); // ... and here we use it ... oh-oh other.set_rdbuf(nullptr); } diff --git a/arbor/io/locked_ostream.hpp b/arbor/io/locked_ostream.hpp index 20ecfc74a6..07e9efd93a 100644 --- a/arbor/io/locked_ostream.hpp +++ b/arbor/io/locked_ostream.hpp @@ -13,7 +13,7 @@ struct locked_ostream: std::ostream { locked_ostream(std::streambuf *b); locked_ostream(locked_ostream&& other); - ~locked_ostream(); + ~locked_ostream() override; std::unique_lock guard(); diff --git a/arbor/io/trace.hpp b/arbor/io/trace.hpp index 5b50b7d60a..bba46e784b 100644 --- a/arbor/io/trace.hpp +++ b/arbor/io/trace.hpp @@ -56,7 +56,7 @@ namespace impl { lock_(this->guard()) {} - ~emit_nl_locked() { + ~emit_nl_locked() override { if (rdbuf()) { (*this) << std::endl; } diff --git a/arbor/label_resolution.hpp b/arbor/label_resolution.hpp index 9b30a41fa3..f53067bcf7 100644 --- a/arbor/label_resolution.hpp +++ b/arbor/label_resolution.hpp @@ -88,7 +88,7 @@ class ARB_ARBOR_API label_resolution_map { struct ARB_ARBOR_API round_robin_state { cell_lid_type state = 0; - round_robin_state() : state(0) {}; + round_robin_state() = default; round_robin_state(cell_lid_type state) : state(state) {}; cell_lid_type get(); lid_hopefully update(const label_resolution_map::range_set& range); @@ -96,7 +96,7 @@ struct ARB_ARBOR_API round_robin_state { struct ARB_ARBOR_API round_robin_halt_state { cell_lid_type state = 0; - round_robin_halt_state() : state(0) {}; + round_robin_halt_state() = default; round_robin_halt_state(cell_lid_type state) : state(state) {}; cell_lid_type get(); lid_hopefully update(const label_resolution_map::range_set& range); diff --git a/arbor/lif_cell_group.cpp b/arbor/lif_cell_group.cpp index 4597ff4084..ea1062e0c9 100644 --- a/arbor/lif_cell_group.cpp +++ b/arbor/lif_cell_group.cpp @@ -94,15 +94,17 @@ void lif_cell_group::reset() { } // produce voltage V_m at t1, given cell state at t0 and no spikes in [t0, t1) -static double +namespace { +double lif_decay(const lif_cell& cell, double t0, double t1) { return (cell.V_m - cell.E_L)*exp((t0 - t1)/cell.tau_m) + cell.E_L; } +} // Advances a single cell (lid) with the exact solution (jumps can be arbitrary). // Parameter dt is ignored, since we make jumps between two consecutive spikes. void lif_cell_group::advance_cell(time_type tfinal, - time_type dt, + time_type /*dt*/, cell_gid_type lid, const event_lane_subrange& event_lanes) { const auto gid = gids_[lid]; diff --git a/arbor/mechcat.cpp b/arbor/mechcat.cpp index 02c537a115..0d939bc467 100644 --- a/arbor/mechcat.cpp +++ b/arbor/mechcat.cpp @@ -247,7 +247,8 @@ struct catalogue_state { const std::string* base = &name; if (!defined(name)) { - if ((implicit_deriv = derive(name))) { + implicit_deriv = derive(name); + if (implicit_deriv) { base = &implicit_deriv->parent; } else { diff --git a/arbor/memory/allocator.hpp b/arbor/memory/allocator.hpp index 1c2a79f00e..c06c3eba78 100644 --- a/arbor/memory/allocator.hpp +++ b/arbor/memory/allocator.hpp @@ -191,7 +191,7 @@ class allocator : public Policy { return nullptr; } - void deallocate(pointer p, size_type cnt) { + void deallocate(pointer p, size_type) { if (p) { free_policy(p); } @@ -240,7 +240,7 @@ namespace util { template <> struct type_printer{ static std::string print() { - return std::string("device_policy"); + return "device_policy"; } }; diff --git a/arbor/memory/array.hpp b/arbor/memory/array.hpp index 1bbdbc3613..f2dd9f7057 100644 --- a/arbor/memory/array.hpp +++ b/arbor/memory/array.hpp @@ -145,7 +145,7 @@ class array : array(const array& other) : base(coordinator_type().allocate(other.size())) { - static_assert(impl::is_array_t::value, ""); + static_assert(impl::is_array_t::value); #ifdef VERBOSE std::cerr << util::green("array(array&)") << " " << util::type_printer::print() diff --git a/arbor/memory/array_view.hpp b/arbor/memory/array_view.hpp index 0180f6fb5a..67f1348e6b 100644 --- a/arbor/memory/array_view.hpp +++ b/arbor/memory/array_view.hpp @@ -204,7 +204,7 @@ class array_view { typename Other, typename = std::enable_if_t< impl::is_array::value > > - array_view operator=(Other&& other) { + array_view& operator=(Other&& other) { #if VERBOSE std::cerr << util::pretty_printer::print(*this) << "::" << util::blue("operator=") << "(" @@ -278,6 +278,9 @@ class array_view { return coordinator_type::alignment(); } + // disallow constructors that imply allocation of memory + array_view(std::size_t n) = delete; + protected : template < typename U, typename C> friend void impl::reset(array_view&, U*, std::size_t); @@ -302,9 +305,6 @@ protected : size_ = n; } - // disallow constructors that imply allocation of memory - array_view(std::size_t n) = delete; - coordinator_type coordinator_; pointer pointer_; size_type size_; @@ -387,7 +387,7 @@ class const_array_view { typename Other, typename = std::enable_if_t< impl::is_array::value > > - const_array_view operator=(Other&& other) { + const_array_view& operator=(Other&& other) { #if VERBOSE std::cerr << util::pretty_printer::print(*this) << "::" << util::blue("operator=") << "(" diff --git a/arbor/memory/definitions.hpp b/arbor/memory/definitions.hpp index c2b3679f6b..97f1b29f54 100644 --- a/arbor/memory/definitions.hpp +++ b/arbor/memory/definitions.hpp @@ -8,8 +8,8 @@ namespace arb { namespace memory { namespace types { - typedef std::ptrdiff_t difference_type; - typedef std::size_t size_type; + using difference_type = std::ptrdiff_t; + using size_type = std::size_t; } // namespace types namespace util { @@ -19,8 +19,8 @@ namespace util { template struct pretty_printer{ - static std::string print(const T& val) { - return std::string("T()"); + static std::string print(const T& /*val*/) { + return "T()"; } }; @@ -53,7 +53,7 @@ namespace util { template struct pretty_printer>{ - typedef std::pair T; + using T = std::pair; static std::string print(const T& val) { std::stringstream str; str << type_printer::print() @@ -74,28 +74,28 @@ namespace util { template <> struct type_printer{ static std::string print() { - return std::string("float"); + return "float"; } }; template <> struct type_printer{ static std::string print() { - return std::string("double"); + return "double"; } }; template <> struct type_printer{ static std::string print() { - return std::string("size_t"); + return "size_t"; } }; template <> struct type_printer{ static std::string print() { - return std::string("int"); + return "int"; } }; diff --git a/arbor/memory/device_coordinator.hpp b/arbor/memory/device_coordinator.hpp index f2e0afa8d2..2322283657 100644 --- a/arbor/memory/device_coordinator.hpp +++ b/arbor/memory/device_coordinator.hpp @@ -39,7 +39,7 @@ namespace util { template struct pretty_printer>{ - static std::string print(const device_coordinator& val) { + static std::string print(const device_coordinator&) { return type_printer>::print(); } }; @@ -60,10 +60,11 @@ class const_device_reference { return tmp; } -protected: template - void operator =(Other&&) {} + const_device_reference& operator=(Other&&) = delete; + +protected: const_pointer pointer_; }; @@ -228,7 +229,7 @@ class device_coordinator { // generates compile time error if there is an attempt to copy from memory // that is managed by a coordinator for which there is no specialization template - void copy(const array_view& from, view_type& to) { + void copy(const array_view&, view_type&) { static_assert(true, "device_coordinator: unable to copy from other Coordinator"); } diff --git a/arbor/memory/gpu_wrappers.cpp b/arbor/memory/gpu_wrappers.cpp index fdb76ceb6d..8e6bd9c8f5 100644 --- a/arbor/memory/gpu_wrappers.cpp +++ b/arbor/memory/gpu_wrappers.cpp @@ -87,39 +87,27 @@ LOG_ERROR("memory:: "+std::string(__func__)+"(): no GPU support") namespace arb { namespace memory { -void gpu_memcpy_d2d(void* dest, const void* src, std::size_t n) { - NOGPU; -} +void gpu_memcpy_d2d(void* /*dest*/, const void* /*src*/, std::size_t /*n*/) { NOGPU; } -void gpu_memcpy_d2h(void* dest, const void* src, std::size_t n) { - NOGPU; -} +void gpu_memcpy_d2h(void* /*dest*/, const void* /*src*/, std::size_t /*n*/) { NOGPU; } -void gpu_memcpy_h2d(void* dest, const void* src, std::size_t n) { - NOGPU; -} +void gpu_memcpy_h2d(void* /*dest*/, const void* /*src*/, std::size_t /*n*/) { NOGPU; } -void gpu_memcpy_h2d_async(void* dest, const void* src, std::size_t n) { - NOGPU; -} +void gpu_memcpy_h2d_async(void* /*dest*/, const void* /*src*/, std::size_t /*n*/) { NOGPU; } -void* gpu_host_register(void* ptr, std::size_t size) { +void* gpu_host_register(void*, std::size_t) { NOGPU; return nullptr; } -void gpu_host_unregister(void* ptr) { - NOGPU; -} +void gpu_host_unregister(void*) { NOGPU; } -void* gpu_malloc(std::size_t n) { +void* gpu_malloc(std::size_t) { NOGPU; return nullptr; } -void gpu_free(void* ptr) { - NOGPU; -} +void gpu_free(void*) { NOGPU; } } // namespace memory } // namespace arb diff --git a/arbor/memory/host_coordinator.hpp b/arbor/memory/host_coordinator.hpp index 37a68b61db..b5fababd86 100644 --- a/arbor/memory/host_coordinator.hpp +++ b/arbor/memory/host_coordinator.hpp @@ -24,7 +24,7 @@ class device_coordinator; namespace util { template - struct type_printer>{ + struct type_printer>{ static std::string print() { #if VERBOSE>1 return util::white("host_coordinator") + "<" + type_printer::print() @@ -36,9 +36,9 @@ namespace util { }; template - struct pretty_printer>{ - static std::string print(const host_coordinator& val) { - return type_printer>::print();; + struct pretty_printer>{ + static std::string print(const host_coordinator& /*val*/) { + return type_printer>::print();; } }; } // namespace util diff --git a/arbor/morph/embed_pwlin.cpp b/arbor/morph/embed_pwlin.cpp index a078421b9b..3eacce6720 100644 --- a/arbor/morph/embed_pwlin.cpp +++ b/arbor/morph/embed_pwlin.cpp @@ -189,10 +189,11 @@ double embed_pwlin::integrate_ixa(const mcable& c) const { } // Integrate piecewise function over a cable: - -static pw_constant_fn restrict(const pw_constant_fn& g, double left, double right) { +namespace { +pw_constant_fn restrict(const pw_constant_fn& g, double left, double right) { return pw_zip_with(g, pw_elements{{left, right}}); } +} double embed_pwlin::integrate_length(const mcable& c, const pw_constant_fn& g) const { return integrate_length(c.branch, restrict(g, c.prox_pos, c.dist_pos)); diff --git a/arbor/morph/locset.cpp b/arbor/morph/locset.cpp index f9a956839a..28d3dff664 100644 --- a/arbor/morph/locset.cpp +++ b/arbor/morph/locset.cpp @@ -38,11 +38,11 @@ ARB_ARBOR_API locset nil() { return locset{nil_{}}; } -mlocation_list thingify_(const nil_& x, const mprovider&) { +mlocation_list thingify_(const nil_&, const mprovider&) { return {}; } -std::ostream& operator<<(std::ostream& o, const nil_& x) { +std::ostream& operator<<(std::ostream& o, const nil_&) { return o << "(locset-nil)"; } @@ -114,7 +114,7 @@ mlocation_list thingify_(const terminal_&, const mprovider& p) { return locs; } -std::ostream& operator<<(std::ostream& o, const terminal_& x) { +std::ostream& operator<<(std::ostream& o, const terminal_&) { return o << "(terminal)"; } @@ -258,11 +258,11 @@ ARB_ARBOR_API locset root() { return locset{root_{}}; } -mlocation_list thingify_(const root_&, const mprovider& p) { +mlocation_list thingify_(const root_&, const mprovider&) { return {mlocation{0, 0.}}; } -std::ostream& operator<<(std::ostream& o, const root_& x) { +std::ostream& operator<<(std::ostream& o, const root_&) { return o << "(root)"; } @@ -278,7 +278,7 @@ mlocation_list thingify_(const segments_&, const mprovider& p) { return p.embedding().segment_ends(); } -std::ostream& operator<<(std::ostream& o, const segments_& x) { +std::ostream& operator<<(std::ostream& o, const segments_&) { return o << "(segment-boundaries)"; } diff --git a/arbor/morph/morphexcept.cpp b/arbor/morph/morphexcept.cpp index 0090040a49..6a415c58e8 100644 --- a/arbor/morph/morphexcept.cpp +++ b/arbor/morph/morphexcept.cpp @@ -10,9 +10,11 @@ namespace arb { using arb::util::pprintf; -static std::string msize_string(msize_t x) { +namespace { +std::string msize_string(msize_t x) { return x==mnpos? "mnpos": pprintf("{}", x); } +} invalid_mlocation::invalid_mlocation(mlocation loc): morphology_error(pprintf("invalid mlocation {}", loc)), diff --git a/arbor/morph/mprovider.cpp b/arbor/morph/mprovider.cpp index 1308258745..6178823a1d 100644 --- a/arbor/morph/mprovider.cpp +++ b/arbor/morph/mprovider.cpp @@ -39,9 +39,9 @@ void mprovider::init() { // provided label_dict, and the maps updated accordingly. Post-initialization, // label_dict_ptr will be null, and concrete regions/locsets will only be retrieved // from the maps established during initialization. - +namespace { template -static const auto& try_lookup(const mprovider& provider, const std::string& name, RegOrLocMap& map, const LabelDictMap* dict_ptr) { +const auto& try_lookup(const mprovider& provider, const std::string& name, RegOrLocMap& map, const LabelDictMap* dict_ptr) { auto it = map.find(name); if (it==map.end()) { if (dict_ptr) { @@ -65,6 +65,7 @@ static const auto& try_lookup(const mprovider& provider, const std::string& name return it->second.value(); } } +} const mextent& mprovider::region(const std::string& name) const { const auto* regions_ptr = label_dict_ptr? &(label_dict_ptr->regions()): nullptr; diff --git a/arbor/morph/place_pwlin.cpp b/arbor/morph/place_pwlin.cpp index 8e49094ca3..cb148ab112 100644 --- a/arbor/morph/place_pwlin.cpp +++ b/arbor/morph/place_pwlin.cpp @@ -28,8 +28,9 @@ struct place_pwlin_data { segment_index(n_branch) {} }; +namespace { -static mpoint interpolate_segment(const std::pair& bounds, const msegment& seg, double pos) { +mpoint interpolate_segment(const std::pair& bounds, const msegment& seg, double pos) { if (bounds.first==bounds.second) { return seg.prox; } @@ -46,41 +47,12 @@ static mpoint interpolate_segment(const std::pair& bounds, const } template -static bool is_degenerate(const util::pw_elements& pw) { +bool is_degenerate(const util::pw_elements& pw) { return pw.bounds().second==0; } -mpoint place_pwlin::at(mlocation loc) const { - const auto& pw_index = data_->segment_index.at(loc.branch); - double pos = is_degenerate(pw_index)? 0: loc.pos; - - auto index = pw_index(pos); - return interpolate_segment(index.extent, data_->segments.at(index), pos); -} - -std::vector place_pwlin::all_at(mlocation loc) const { - std::vector result; - const auto& pw_index = data_->segment_index.at(loc.branch); - double pos = is_degenerate(pw_index)? 0: loc.pos; - - for (auto index: util::make_range(pw_index.equal_range(pos))) { - auto bounds = index.extent; - auto seg = data_->segments.at(index); - - // Add both ends of zero length segment, if they differ. - if (bounds.first==bounds.second && seg.prox!=seg.dist) { - result.push_back(seg.prox); - result.push_back(seg.dist); - } - else { - result.push_back(interpolate_segment(bounds, seg, pos)); - } - } - return result; -} - template -static std::vector extent_segments_impl(const place_pwlin_data& data, const mextent& extent) { +std::vector extent_segments_impl(const place_pwlin_data& data, const mextent& extent) { std::vector result; for (mcable c: extent) { @@ -126,6 +98,37 @@ static std::vector extent_segments_impl(const place_pwlin_data& data, return result; } +} +mpoint place_pwlin::at(mlocation loc) const { + const auto& pw_index = data_->segment_index.at(loc.branch); + double pos = is_degenerate(pw_index)? 0: loc.pos; + + auto index = pw_index(pos); + return interpolate_segment(index.extent, data_->segments.at(index), pos); +} + +std::vector place_pwlin::all_at(mlocation loc) const { + std::vector result; + const auto& pw_index = data_->segment_index.at(loc.branch); + double pos = is_degenerate(pw_index)? 0: loc.pos; + + for (auto index: util::make_range(pw_index.equal_range(pos))) { + auto bounds = index.extent; + auto seg = data_->segments.at(index); + + // Add both ends of zero length segment, if they differ. + if (bounds.first==bounds.second && seg.prox!=seg.dist) { + result.push_back(seg.prox); + result.push_back(seg.dist); + } + else { + result.push_back(interpolate_segment(bounds, seg, pos)); + } + } + return result; +} + + std::vector place_pwlin::all_segments(const mextent& extent) const { return extent_segments_impl(*data_, extent); } diff --git a/arbor/morph/region.cpp b/arbor/morph/region.cpp index 3d6fed9645..fe43bcd9cc 100644 --- a/arbor/morph/region.cpp +++ b/arbor/morph/region.cpp @@ -37,11 +37,11 @@ ARB_ARBOR_API region nil() { return region{nil_{}}; } -mextent thingify_(const nil_& x, const mprovider&) { +mextent thingify_(const nil_&, const mprovider&) { return mextent{}; } -std::ostream& operator<<(std::ostream& o, const nil_& x) { +std::ostream& operator<<(std::ostream& o, const nil_&) { return o << "(region-nil)"; } @@ -210,7 +210,7 @@ mextent thingify_(const all_&, const mprovider& p) { return {branches}; } -std::ostream& operator<<(std::ostream& o, const all_& t) { +std::ostream& operator<<(std::ostream& o, const all_&) { return o << "(all)"; } diff --git a/arbor/partition_load_balance.cpp b/arbor/partition_load_balance.cpp index 01874f6b50..80305bdcea 100644 --- a/arbor/partition_load_balance.cpp +++ b/arbor/partition_load_balance.cpp @@ -226,7 +226,7 @@ ARB_ARBOR_API domain_decomposition partition_load_balance( // global all-to-all to gather a local copy of the global gid list on each node. auto global_gids = dist->gather_gids(local_gids); - return domain_decomposition(rec, ctx, groups); + return {rec, ctx, groups}; } } // namespace arb diff --git a/arbor/profile/clock.cpp b/arbor/profile/clock.cpp index 2362b2461e..876f2ad116 100644 --- a/arbor/profile/clock.cpp +++ b/arbor/profile/clock.cpp @@ -1,5 +1,5 @@ #define _POSIX_C_SOURCE 200809L -#include +#include // Keep implementation out of header in order to avoid // global namespace pollution from . diff --git a/arbor/profile/meter_manager.cpp b/arbor/profile/meter_manager.cpp index 3a805dde5f..c85e056429 100644 --- a/arbor/profile/meter_manager.cpp +++ b/arbor/profile/meter_manager.cpp @@ -109,12 +109,11 @@ ARB_ARBOR_API meter_report make_meter_report(const meter_manager& manager, conte meter_report report; // Add the times to the meter outputs - report.meters.push_back(measurement("time", "s", manager.times(), ctx)); + report.meters.emplace_back("time", "s", manager.times(), ctx); // Gather the meter outputs. for (auto& m: manager.meters()) { - report.meters.push_back( - measurement(m->name(), m->units(), m->measurements(), ctx)); + report.meters.emplace_back(m->name(), m->units(), m->measurements(), ctx); } // Gather a vector with the names of the node that each rank is running on. diff --git a/arbor/profile/profiler.cpp b/arbor/profile/profiler.cpp index fccb33ba87..eaffed8ff2 100644 --- a/arbor/profile/profiler.cpp +++ b/arbor/profile/profiler.cpp @@ -14,7 +14,6 @@ namespace arb { namespace profile { using timer_type = timer<>; -using util::make_span; #ifdef ARB_HAVE_PROFILING namespace { @@ -421,10 +420,10 @@ ARB_ARBOR_API std::ostream& print_profiler_summary(std::ostream& os, double limi ARB_ARBOR_API void profiler_leave() {} ARB_ARBOR_API void profiler_enter(region_id_type) {} ARB_ARBOR_API profile profiler_summary(); -ARB_ARBOR_API profile profiler_summary() {return profile();} +ARB_ARBOR_API profile profiler_summary() {return {};} ARB_ARBOR_API region_id_type profiler_region_id(const std::string&) {return 0;} ARB_ARBOR_API std::ostream& operator<<(std::ostream& o, const profile&) {return o;} -ARB_ARBOR_API std::ostream& profiler_print_summary(std::ostream& os, double limit) { return os; } +ARB_ARBOR_API std::ostream& profiler_print_summary(std::ostream& os, double) { return os; } #endif // ARB_HAVE_PROFILING diff --git a/arbor/s_expr.cpp b/arbor/s_expr.cpp index 71fbc2692c..9e3135bf1b 100644 --- a/arbor/s_expr.cpp +++ b/arbor/s_expr.cpp @@ -79,13 +79,10 @@ struct s_expr_lexer_error: public arb::arbor_internal_error { {} }; -static std::unordered_map tok_to_keyword = { - {tok::nil, "nil"}, -}; - -static std::unordered_map keyword_to_tok = { - {"nil", tok::nil}, -}; +namespace { +std::unordered_map tok_to_keyword = {{tok::nil, "nil"}}; +std::unordered_map keyword_to_tok = {{"nil", tok::nil}}; +} class lexer { const char* line_start_ = nullptr; diff --git a/arbor/spike_source_cell_group.cpp b/arbor/spike_source_cell_group.cpp index ab4d88e78b..076abc06cb 100644 --- a/arbor/spike_source_cell_group.cpp +++ b/arbor/spike_source_cell_group.cpp @@ -45,7 +45,7 @@ cell_kind spike_source_cell_group::get_cell_kind() const { return cell_kind::spike_source; } -void spike_source_cell_group::advance(epoch ep, time_type dt, const event_lane_subrange& event_lanes) { +void spike_source_cell_group::advance(epoch ep, time_type, const event_lane_subrange&) { PE(advance:sscell); for (auto i: util::count_along(gids_)) { diff --git a/arbor/symmetric_recipe.cpp b/arbor/symmetric_recipe.cpp index 4e7f48d5a5..d5fd934ae7 100644 --- a/arbor/symmetric_recipe.cpp +++ b/arbor/symmetric_recipe.cpp @@ -29,8 +29,8 @@ std::vector symmetric_recipe::connections_on(cell_gid_type i) c std::vector conns = tiled_recipe_->connections_on(i % n_local); - for (unsigned j = 0; j < conns.size(); j++) { - conns[j].source.gid = (conns[j].source.gid + offset) % n_global; + for (auto& conn: conns) { + conn.source.gid = (conn.source.gid + offset) % n_global; } return conns; } @@ -44,4 +44,4 @@ std::any symmetric_recipe::get_global_properties(cell_kind ck) const { return tiled_recipe_->get_global_properties(ck); }; -} //namespace arb \ No newline at end of file +} //namespace arb diff --git a/arbor/timestep_range.hpp b/arbor/timestep_range.hpp index c9a346bbbe..c07344c1c8 100644 --- a/arbor/timestep_range.hpp +++ b/arbor/timestep_range.hpp @@ -95,7 +95,7 @@ class timestep_range { dt = dt < 0 ? (t1-t0) : dt; dt_ = std::max(std::numeric_limits::min(), dt); const time_type delta = (t1<=t0)? 0: t1-t0; - const size_type m = static_cast(delta/dt_); + const auto m = static_cast(delta/dt_); // Allow slightly larger time steps at the end of the epoch in order to avoid tiny time // steps, if the the last time step m*dt_ is at most m floating point representations // smaller than t1_. The tolerable floating point range is approximated by the scaled diff --git a/arbor/util/cbrng.hpp b/arbor/util/cbrng.hpp index 6f78e44942..0fcfb4efad 100644 --- a/arbor/util/cbrng.hpp +++ b/arbor/util/cbrng.hpp @@ -7,6 +7,7 @@ namespace arb { namespace util { +inline std::vector uniform(uint64_t seed, unsigned left, unsigned right) { typedef r123::Threefry2x64 cbrng; std::vector r; @@ -36,6 +37,5 @@ std::vector uniform(uint64_t seed, unsigned left, unsigned right) { } return r; } - } -} \ No newline at end of file +} diff --git a/arbor/util/padded_alloc.hpp b/arbor/util/padded_alloc.hpp index d29908f08a..7d7241525a 100644 --- a/arbor/util/padded_alloc.hpp +++ b/arbor/util/padded_alloc.hpp @@ -68,7 +68,7 @@ struct padded_allocator { return static_cast(mem); } - void deallocate(pointer p, std::size_t n) { + void deallocate(pointer p, std::size_t) { std::free(p); } diff --git a/arbor/util/piecewise.hpp b/arbor/util/piecewise.hpp index 58772ace4c..a6236daae4 100644 --- a/arbor/util/piecewise.hpp +++ b/arbor/util/piecewise.hpp @@ -172,6 +172,7 @@ struct pw_element_proxy { // Compute indices into vertex set corresponding to elements that cover a point x: namespace { +inline std::pair equal_range_indices(const std::vector& vertices, double x) { if (vertices.empty()) return {0, 0}; diff --git a/arbor/util/sentinel.hpp b/arbor/util/sentinel.hpp index f93185e445..937f6feb94 100644 --- a/arbor/util/sentinel.hpp +++ b/arbor/util/sentinel.hpp @@ -178,12 +178,12 @@ using sentinel_iterator_t = std::conditional_t::value, I, sentinel_iterator>; template -sentinel_iterator_t make_sentinel_iterator(const I& i, const S& s) { +sentinel_iterator_t make_sentinel_iterator(const I& i, const S&) { return sentinel_iterator_t(i); } template -sentinel_iterator_t make_sentinel_end(const I& i, const S& s) { +sentinel_iterator_t make_sentinel_end(const I&, const S& s) { return sentinel_iterator_t(s); } diff --git a/arbor/util/strprintf.hpp b/arbor/util/strprintf.hpp index d56115bb86..e6adfc90c4 100644 --- a/arbor/util/strprintf.hpp +++ b/arbor/util/strprintf.hpp @@ -67,12 +67,12 @@ std::string strprintf(const char* fmt, Args&&... args) { thread_local static std::vector buffer(1024); for (;;) { - int n = std::snprintf(buffer.data(), buffer.size(), fmt, impl::sprintf_arg_translate(std::forward(args))...); + auto n = std::snprintf(buffer.data(), buffer.size(), fmt, impl::sprintf_arg_translate(std::forward(args))...); if (n<0) { throw std::system_error(errno, std::generic_category()); } else if ((unsigned)n(n)}; } buffer.resize(2*n); } diff --git a/arbor/util/unwind.cpp b/arbor/util/unwind.cpp index 9594aa3bb5..8298e6f7d4 100644 --- a/arbor/util/unwind.cpp +++ b/arbor/util/unwind.cpp @@ -15,27 +15,36 @@ namespace arb { namespace util { -backtrace::backtrace() { #ifdef WITH_BACKTRACE +backtrace::backtrace() { auto bt = boost::stacktrace::basic_stacktrace{}; for (const auto& f: bt) { frames_.push_back(source_location{f.name(), f.source_file(), f.source_line()}); } -#endif + } std::ostream& operator<<(std::ostream& out, const backtrace& trace) { -#ifdef WITH_BACKTRACE out << "Backtrace:\n"; int ix = 0; for (const auto& f: trace.frames_) { out << std::setw(8) << ix << " " << f.func << " (" << f.file << ":" << f.line << ")\n"; ix++; } -#endif return out; } +#else + +backtrace::backtrace() = default; + +std::ostream& operator<<(std::ostream& out, const backtrace&) { + out << "Backtrace disabled\n"; + return out; +} + +#endif + backtrace& backtrace::pop(std::size_t n) { frames_.erase(frames_.begin(), frames_.begin() + std::min(n, frames_.size())); diff --git a/arborenv/arbenvexcept.cpp b/arborenv/arbenvexcept.cpp index 2e905a3e17..add0cd419d 100644 --- a/arborenv/arbenvexcept.cpp +++ b/arborenv/arbenvexcept.cpp @@ -8,7 +8,7 @@ using namespace std::literals; namespace arbenv { invalid_env_value::invalid_env_value(const std::string& variable, const std::string& value): - arborenv_exception("environment variable \""s+variable+"\" has invalid value \""s+value+"\""s), + arborenv_exception("environment variable \""s + variable + R"(" has invalid value ")" + value + "\""s), env_variable(variable), env_value(value) {} diff --git a/arborenv/read_envvar.cpp b/arborenv/read_envvar.cpp index a39bf453e1..677aafd6aa 100644 --- a/arborenv/read_envvar.cpp +++ b/arborenv/read_envvar.cpp @@ -11,11 +11,12 @@ using namespace std::literals; namespace arbenv { -static std::optional read_env_integer_(const char* env_var, bool throw_on_err) { +namespace { +std::optional read_env_integer_(const char* env_var, bool throw_on_err) { const char* str = std::getenv(env_var); if (!str || !*str) return std::nullopt; - char* end = 0; + char* end = nullptr; errno = 0; long long v = std::strtoll(str, &end, 10); bool out_of_range = errno==ERANGE; @@ -37,6 +38,7 @@ static std::optional read_env_integer_(const char* env_var, bool thro return v; } +} std::optional read_env_integer(const char* env_var) { return read_env_integer_(env_var, false); diff --git a/arborio/asc_lexer.cpp b/arborio/asc_lexer.cpp index c51bf87939..ff2922431c 100644 --- a/arborio/asc_lexer.cpp +++ b/arborio/asc_lexer.cpp @@ -82,13 +82,13 @@ inline bool is_valid_symbol_char(char c) { class lexer_impl { const char* line_start_; const char* stream_; - unsigned line_; + unsigned line_ = 0; token token_; public: lexer_impl(const char* begin): - line_start_(begin), stream_(begin), line_(0) + line_start_(begin), stream_(begin) { // Prime the first token. parse(); @@ -125,9 +125,7 @@ class lexer_impl { private: - src_location loc() const { - return src_location(line_+1, stream_-line_start_+1); - } + src_location loc() const { return {line_ + 1, static_cast(stream_ - line_start_ + 1)}; } bool empty() const { return *stream_ == '\0'; @@ -294,7 +292,7 @@ class lexer_impl { symbol += c; ++stream_; - while(1) { + for (;;) { c = *stream_; if(is_valid_symbol_char(c)) { @@ -341,7 +339,7 @@ class lexer_impl { str += c; ++stream_; - while(1) { + for (;;) { c = *stream_; if (std::isdigit(c)) { str += c; diff --git a/arborio/cableio.cpp b/arborio/cableio.cpp index a1bf7ee0cb..27c5718dbb 100644 --- a/arborio/cableio.cpp +++ b/arborio/cableio.cpp @@ -538,6 +538,10 @@ template struct make_unordered_call { evaluator state; + make_unordered_call() = delete; + make_unordered_call(const make_unordered_call&) = delete; + make_unordered_call(make_unordered_call&&) = delete; + template make_unordered_call(F&& f, const char* msg="call"): state(arg_vec_eval(std::forward(f)), unordered_match(), msg) diff --git a/arborio/neurolucida.cpp b/arborio/neurolucida.cpp index 213adaa591..d8fbfbba24 100644 --- a/arborio/neurolucida.cpp +++ b/arborio/neurolucida.cpp @@ -285,7 +285,7 @@ parse_hopefully parse_zsmear(asc::lexer& L) { return s; } -#define PARSE_ZSMEAR(L, X) if (auto rval__ = parse_zsmear(L)) X=*rval__; else return FORWARD_PARSE_ERROR(rval__.error()); +#define PARSE_ZSMEAR(L, X) parse_hopefully parse_point(asc::lexer& L) { // check and consume opening paren @@ -562,7 +562,12 @@ parse_hopefully parse_sub_tree(asc::lexer& L) { } // Ignore zSmear. else if (symbol_matches("zSmear", t)) { - PARSE_ZSMEAR(L, __attribute__((unused)) auto _); + if (auto rval = parse_zsmear(L)) { + __attribute__((unused)) auto _ =*rval; + } + else { + return FORWARD_PARSE_ERROR(rval.error()); + } } else if (t.kind==tok::integer || t.kind==tok::real) { // Assume that this is the first sample. diff --git a/arborio/nml_parse_morphology.cpp b/arborio/nml_parse_morphology.cpp index b1ac16a5f6..37b73c6d6e 100644 --- a/arborio/nml_parse_morphology.cpp +++ b/arborio/nml_parse_morphology.cpp @@ -19,8 +19,6 @@ #include "nml_parse_morphology.hpp" #include "xml.hpp" -using arb::region; -using arb::stitched_morphology; using arb::util::expected; using arb::util::unexpected; using std::optional; @@ -251,10 +249,10 @@ struct neuroml_segment_tree { std::unordered_map> children_; }; -static std::unordered_map> evaluate_segment_groups( - std::vector groups, - const neuroml_segment_tree& segtree) -{ +namespace { +std::unordered_map> +evaluate_segment_groups(std::vector groups, + const neuroml_segment_tree& segtree) { const std::size_t n_group = groups.size(); // Expand subTree/path specifications: @@ -360,7 +358,7 @@ static std::unordered_map> evaluate_segme return group_seg_map; } -static arb::stitched_morphology construct_morphology(const neuroml_segment_tree& segtree) { +arb::stitched_morphology construct_morphology(const neuroml_segment_tree& segtree) { arb::stitch_builder builder; if (segtree.empty()) return arb::stitched_morphology{builder}; @@ -398,6 +396,7 @@ static arb::stitched_morphology construct_morphology(const neuroml_segment_tree& return {std::move(builder)}; } +} nml_morphology_data nml_parse_morphology_element(const xml_node& morph, enum neuroml_options::values options) { @@ -461,7 +460,7 @@ nml_morphology_data nml_parse_morphology_element(const xml_node& morph, if (segments.empty()) return M; // Compute tree now to save further parsing if something goes wrong. - neuroml_segment_tree segtree(std::move(segments)); + neuroml_segment_tree segtree(segments); const char* q_member = "./member"; const char* q_include = "./include"; diff --git a/arborio/swcio.cpp b/arborio/swcio.cpp index 6f23fcaa60..d0b02a545e 100644 --- a/arborio/swcio.cpp +++ b/arborio/swcio.cpp @@ -82,8 +82,8 @@ ARB_ARBORIO_API std::istream& operator>>(std::istream& in, swc_record& record) { } // Parse SWC format data (comments and sequence of SWC records). - -static std::vector sort_and_validate_swc(std::vector records) { +namespace { +std::vector sort_and_validate_swc(std::vector records) { if (records.empty()) return {}; std::unordered_set seen; @@ -112,6 +112,7 @@ static std::vector sort_and_validate_swc(std::vector rec return records; } +} // swc_data swc_data::swc_data(std::vector recs) : diff --git a/lmorpho/lmorpho.cpp b/lmorpho/lmorpho.cpp index cbcba1a35c..29885dfc54 100644 --- a/lmorpho/lmorpho.cpp +++ b/lmorpho/lmorpho.cpp @@ -35,7 +35,7 @@ const char* usage_str = " purkinje Guinea pig Purkinje cells, basd on models and data\n" " from Rapp 1994 and Ascoli 2001.\n"; -int main(int argc, char** argv) { +int main(int, char** argv) { // options int n_morph = 1; std::optional rng_seed = 0; diff --git a/python/strprintf.hpp b/python/strprintf.hpp index 0b0ba223ae..c1ac5f3627 100644 --- a/python/strprintf.hpp +++ b/python/strprintf.hpp @@ -97,7 +97,7 @@ std::string strprintf(const char* fmt, Args&&... args) { else if ((unsigned)n(n)}; } - buffer.resize(2*n); + buffer.resize(2ull*n); } } diff --git a/sup/include/sup/ioutil.hpp b/sup/include/sup/ioutil.hpp index bdc7fc7c68..7f10342131 100644 --- a/sup/include/sup/ioutil.hpp +++ b/sup/include/sup/ioutil.hpp @@ -32,10 +32,10 @@ class basic_null_streambuf: public std::basic_streambuf { using off_type = typename streambuf_type::off_type; using traits_type = typename streambuf_type::traits_type; - virtual ~basic_null_streambuf() = default; + ~basic_null_streambuf() override = default; protected: - std::streamsize xsputn(const char_type* s, std::streamsize count) override { + std::streamsize xsputn(const char_type*, std::streamsize count) override { return count; } @@ -59,7 +59,7 @@ class ARB_SUP_API mask_stream { if (F.mask_ && saved_streambuf) { // re-enable by restoring saved streambuf - O.pword(xindex) = 0; + O.pword(xindex) = nullptr; O.rdbuf(saved_streambuf); } else if (!F.mask_ && !saved_streambuf) { diff --git a/sup/include/sup/path.hpp b/sup/include/sup/path.hpp index 823a68500d..0731c01357 100644 --- a/sup/include/sup/path.hpp +++ b/sup/include/sup/path.hpp @@ -59,7 +59,7 @@ class posix_path { posix_path(Iter b, Iter e) { assign(b, e); } template - posix_path& operator=(Source&& source) { return assign(std::forward(source)); } + posix_path& operator=(Source&& source) { assign(std::forward(source)); return *this; } posix_path& assign(const posix_path& other) { p_ = other.p_; @@ -177,19 +177,19 @@ class posix_path { } posix_path filename() const { - auto i = p_.rfind('/'); + auto i = p_.rfind(preferred_separator); return i==std::string::npos? *this: posix_path(p_.substr(i+1)); } bool has_filename() const { if (p_.empty()) return false; - auto i = p_.rfind('/'); + auto i = p_.rfind(preferred_separator); return i==std::string::npos || i+1dir = opendir(p.c_str()))) { + state_->dir = opendir(p.c_str()); + if (state_->dir) { state_->dir_path = p; increment(ec); return; @@ -95,9 +96,11 @@ posix_directory_iterator::posix_directory_iterator(const path& p, directory_opti ec = std::error_code(errno, std::generic_category()); } -static inline bool is_dot_or_dotdot(const char* s) { +namespace { +inline bool is_dot_or_dotdot(const char* s) { return *s=='.' && (!s[1] || (s[1]=='.' && !s[2])); } +} posix_directory_iterator& posix_directory_iterator::increment(std::error_code &ec) { enum file_type type = file_type::none; From 49fb67db3d290012429981b16e3efd5a30ecf45f Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Thu, 4 May 2023 18:19:08 +0200 Subject: [PATCH 03/17] Solve the issues in parse_helper w/o breaking tests. --- arborio/parse_helpers.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arborio/parse_helpers.hpp b/arborio/parse_helpers.hpp index 5b0c37f9a7..85d873eaa7 100644 --- a/arborio/parse_helpers.hpp +++ b/arborio/parse_helpers.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace arborio { using namespace arb; @@ -71,7 +72,7 @@ struct call_match { } template - bool match_args_impl(const std::vector& args) const { + bool match_args_impl(const std::vector&) const { return true; } @@ -197,6 +198,9 @@ template struct make_call { evaluator state; + make_call(make_call&&) = delete; + make_call(const make_call&) = delete; + template make_call(F&& f, const char* msg="call"): state(call_eval(std::forward(f)), call_match(), msg) @@ -211,6 +215,9 @@ template struct make_fold { evaluator state; + make_fold(make_fold&&) = delete; + make_fold(const make_fold&) = delete; + template make_fold(F&& f, const char* msg="fold"): state(fold_eval(std::forward(f)), fold_match(), msg) @@ -226,6 +233,8 @@ template struct make_conversion_fold { evaluator state; + make_conversion_fold(make_conversion_fold&&) = delete; + template make_conversion_fold(F&& f, const char* msg = "fold_conversion"): state(fold_conversion_eval(std::forward(f)), @@ -295,6 +304,9 @@ template struct make_arg_vec_call { evaluator state; + make_arg_vec_call(make_arg_vec_call&&) = delete; + make_arg_vec_call(const make_arg_vec_call&) = delete; + template make_arg_vec_call(F&& f, const char* msg="argument vector"): state(arg_vec_eval(std::forward(f)), arg_vec_match(), msg) From 7f5fe466dbbf0e00898ff3696eefc07b157ab138 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Fri, 5 May 2023 16:35:51 +0200 Subject: [PATCH 04/17] Add performance fixes. --- arbor/arbexcept.cpp | 2 +- arbor/distributed_context.hpp | 2 +- arbor/fvm_lowered_cell.hpp | 4 +- arbor/include/arbor/arbexcept.hpp | 2 +- arbor/include/arbor/cable_cell_param.hpp | 4 +- arbor/include/arbor/mechcat.hpp | 4 +- arbor/include/arbor/morph/isometry.hpp | 2 +- arbor/include/arbor/morph/morphology.hpp | 2 +- arbor/include/arbor/morph/mprovider.hpp | 4 +- arbor/include/arbor/morph/region.hpp | 7 +-- arbor/include/arbor/morph/stitch.hpp | 10 ++-- arbor/include/arbor/s_expr.hpp | 12 ++--- arbor/include/arbor/simulation.hpp | 8 +-- arbor/include/arbor/util/expected.hpp | 8 +-- arbor/io/locked_ostream.cpp | 6 +-- arbor/io/locked_ostream.hpp | 2 +- arbor/label_resolution.cpp | 2 +- arbor/mechcat.cpp | 4 +- arbor/memory/array.hpp | 4 +- arbor/morph/cv_data.cpp | 2 +- arbor/morph/label_dict.cpp | 3 +- arbor/morph/locset.cpp | 1 - arbor/morph/morphology.cpp | 5 +- arbor/morph/region.cpp | 4 +- arbor/morph/stitch.cpp | 6 +-- arbor/partition_load_balance.cpp | 1 + arbor/s_expr.cpp | 2 +- arbor/simulation.cpp | 10 ++-- arbor/thread_private_spike_store.cpp | 2 +- arbor/thread_private_spike_store.hpp | 2 +- arbor/threading/threading.hpp | 6 +-- arbor/tree.cpp | 2 +- arbor/tree.hpp | 2 +- arbor/util/counter.hpp | 4 +- arbor/util/filter.hpp | 4 +- arbor/util/ordered_forest.hpp | 2 +- arbor/util/piecewise.hpp | 6 +-- arbor/util/range.hpp | 4 +- arbor/util/sentinel.hpp | 4 +- arbor/util/transform.hpp | 4 +- arborenv/arbenvexcept.cpp | 6 +-- arborenv/include/arborenv/arbenvexcept.hpp | 2 +- arborio/cableio.cpp | 8 +-- arborio/cv_policy_parse.cpp | 4 +- arborio/include/arborio/neurolucida.hpp | 4 +- arborio/include/arborio/neuroml.hpp | 4 +- arborio/neurolucida.cpp | 6 +-- arborio/neuroml.cpp | 7 +-- arborio/xml.hpp | 58 ++++++++++++---------- lmorpho/lsystem.cpp | 2 +- lmorpho/lsystem.hpp | 2 +- 51 files changed, 138 insertions(+), 130 deletions(-) diff --git a/arbor/arbexcept.cpp b/arbor/arbexcept.cpp index f4db0cc15c..29b4556444 100644 --- a/arbor/arbexcept.cpp +++ b/arbor/arbexcept.cpp @@ -73,7 +73,7 @@ bad_probeset_id::bad_probeset_id(cell_member_type probeset_id): probeset_id(probeset_id) {} -gj_unsupported_lid_selection_policy::gj_unsupported_lid_selection_policy(cell_gid_type gid, cell_tag_type label): +gj_unsupported_lid_selection_policy::gj_unsupported_lid_selection_policy(cell_gid_type gid, const cell_tag_type& label): arbor_exception(pprintf("Model building error on cell {}: gap junction site label \"{}\" must be univalent.", gid, label)), gid(gid), label(label) diff --git a/arbor/distributed_context.hpp b/arbor/distributed_context.hpp index 3196ebaeae..f8481000c2 100644 --- a/arbor/distributed_context.hpp +++ b/arbor/distributed_context.hpp @@ -84,7 +84,7 @@ class distributed_context { return impl_->gather_cell_labels_and_gids(local_labels_and_gids); } - std::vector gather(std::string value, int root) const { + std::vector gather(const std::string& value, int root) const { return impl_->gather(value, root); } diff --git a/arbor/fvm_lowered_cell.hpp b/arbor/fvm_lowered_cell.hpp index 602ac7e99d..236e00a935 100644 --- a/arbor/fvm_lowered_cell.hpp +++ b/arbor/fvm_lowered_cell.hpp @@ -133,8 +133,8 @@ struct missing_probe_info { struct fvm_probe_data { fvm_probe_data() = default; - fvm_probe_data(fvm_probe_scalar p): info(std::move(p)) {} - fvm_probe_data(fvm_probe_interpolated p): info(std::move(p)) {} + fvm_probe_data(fvm_probe_scalar p): info(p) {} + fvm_probe_data(fvm_probe_interpolated p): info(p) {} fvm_probe_data(fvm_probe_multi p): info(std::move(p)) {} fvm_probe_data(fvm_probe_weighted_multi p): info(std::move(p)) {} fvm_probe_data(fvm_probe_interpolated_multi p): info(std::move(p)) {} diff --git a/arbor/include/arbor/arbexcept.hpp b/arbor/include/arbor/arbexcept.hpp index e61f348e46..f368463bac 100644 --- a/arbor/include/arbor/arbexcept.hpp +++ b/arbor/include/arbor/arbexcept.hpp @@ -87,7 +87,7 @@ struct ARB_SYMBOL_VISIBLE gj_kind_mismatch: arbor_exception { }; struct ARB_SYMBOL_VISIBLE gj_unsupported_lid_selection_policy: arbor_exception { - gj_unsupported_lid_selection_policy(cell_gid_type gid, cell_tag_type label); + gj_unsupported_lid_selection_policy(cell_gid_type gid, const cell_tag_type& label); cell_gid_type gid; cell_tag_type label; }; diff --git a/arbor/include/arbor/cable_cell_param.hpp b/arbor/include/arbor/cable_cell_param.hpp index 42748a57a3..7c3d981620 100644 --- a/arbor/include/arbor/cable_cell_param.hpp +++ b/arbor/include/arbor/cable_cell_param.hpp @@ -249,8 +249,8 @@ struct ARB_SYMBOL_VISIBLE scaled_mechanism { explicit scaled_mechanism(TaggedMech m) : t_mech(std::move(m)) {} - scaled_mechanism& scale(std::string name, iexpr expr) { - scale_expr.insert_or_assign(name, expr); + scaled_mechanism& scale(const std::string& name, iexpr expr) { + scale_expr.insert_or_assign(name, std::move(expr)); return *this; } }; diff --git a/arbor/include/arbor/mechcat.hpp b/arbor/include/arbor/mechcat.hpp index 45b30f83d3..9219fe8727 100644 --- a/arbor/include/arbor/mechcat.hpp +++ b/arbor/include/arbor/mechcat.hpp @@ -45,8 +45,8 @@ class ARB_ARBOR_API mechanism_catalogue { using value_type = double; mechanism_catalogue(); - mechanism_catalogue(mechanism_catalogue&& other); - mechanism_catalogue& operator=(mechanism_catalogue&& other); + mechanism_catalogue(mechanism_catalogue&& other) noexcept; + mechanism_catalogue& operator=(mechanism_catalogue&& other) noexcept; mechanism_catalogue(const mechanism_catalogue& other); mechanism_catalogue& operator=(const mechanism_catalogue& other); diff --git a/arbor/include/arbor/morph/isometry.hpp b/arbor/include/arbor/morph/isometry.hpp index 54d958917f..df30a305d5 100644 --- a/arbor/include/arbor/morph/isometry.hpp +++ b/arbor/include/arbor/morph/isometry.hpp @@ -33,7 +33,7 @@ struct ARB_ARBOR_API isometry { double tx_ = 0, ty_ = 0, tz_ = 0; isometry(quaternion q, double tx, double ty, double tz): - q_(std::move(q)), tx_(tx), ty_(ty), tz_(tz) {} + q_(q), tx_(tx), ty_(ty), tz_(tz) {} public: static isometry translate(double x, double y, double z) { diff --git a/arbor/include/arbor/morph/morphology.hpp b/arbor/include/arbor/morph/morphology.hpp index 68ce34a0ef..e1a4532bf0 100644 --- a/arbor/include/arbor/morph/morphology.hpp +++ b/arbor/include/arbor/morph/morphology.hpp @@ -18,7 +18,7 @@ class ARB_ARBOR_API morphology { std::shared_ptr impl_; public: - morphology(segment_tree m); + morphology(const segment_tree& m); morphology(); // Empty/default-constructed morphology? diff --git a/arbor/include/arbor/morph/mprovider.hpp b/arbor/include/arbor/morph/mprovider.hpp index fbd8bcfc40..ca6b4612ef 100644 --- a/arbor/include/arbor/morph/mprovider.hpp +++ b/arbor/include/arbor/morph/mprovider.hpp @@ -16,8 +16,8 @@ namespace arb { using concrete_embedding = embed_pwlin; struct ARB_ARBOR_API mprovider { - mprovider(arb::morphology m, const label_dict& dict): mprovider(m, &dict) {} - explicit mprovider(arb::morphology m): mprovider(m, nullptr) {} + mprovider(arb::morphology m, const label_dict& dict): mprovider(std::move(m), &dict) {} + explicit mprovider(arb::morphology m): mprovider(std::move(m), nullptr) {} // Throw exception on missing or recursive definition. const mextent& region(const std::string& name) const; diff --git a/arbor/include/arbor/morph/region.hpp b/arbor/include/arbor/morph/region.hpp index 03807b7f69..4123dd1a2e 100644 --- a/arbor/include/arbor/morph/region.hpp +++ b/arbor/include/arbor/morph/region.hpp @@ -29,7 +29,8 @@ class ARB_SYMBOL_VISIBLE region { explicit region(const Impl& impl): impl_(new wrap(impl)) {} - region(region&& other) = default; + region(region&& other) noexcept = default; + region& operator=(region&& other) noexcept = default; // The default constructor creates an empty "nil" region. region(); @@ -81,8 +82,8 @@ class ARB_SYMBOL_VISIBLE region { friend region intersect(region, region); template - friend region intersect(region l, region r, Args... args) { - return intersect(intersect(std::move(l), std::move(r)), std::move(args)...); + friend region intersect(const region& l, const region& r, Args... args) { + return intersect(intersect(l, r), std::move(args)...); } private: diff --git a/arbor/include/arbor/morph/stitch.hpp b/arbor/include/arbor/morph/stitch.hpp index c64b46e1de..63fad689c0 100644 --- a/arbor/include/arbor/morph/stitch.hpp +++ b/arbor/include/arbor/morph/stitch.hpp @@ -32,11 +32,11 @@ struct mstitch { int tag; mstitch(std::string id, mpoint prox, mpoint dist, int tag = 0): - id(std::move(id)), prox(std::move(prox)), dist(std::move(dist)), tag(tag) + id(std::move(id)), prox(prox), dist(dist), tag(tag) {} mstitch(std::string id, mpoint dist, int tag = 0): - id(std::move(id)), dist(std::move(dist)), tag(tag) + id(std::move(id)), dist(dist), tag(tag) {} }; @@ -47,10 +47,10 @@ struct ARB_ARBOR_API stitch_builder { stitch_builder(); stitch_builder(const stitch_builder&) = delete; - stitch_builder(stitch_builder&&); + stitch_builder(stitch_builder&&) noexcept; stitch_builder& operator=(const stitch_builder&) = delete; - stitch_builder& operator=(stitch_builder&&); + stitch_builder& operator=(stitch_builder&&) noexcept; // Make a new stitch in the morphology, return reference to self. // @@ -78,7 +78,7 @@ struct ARB_ARBOR_API stitched_morphology { stitched_morphology(stitch_builder&&); // implicit stitched_morphology(const stitched_morphology&) = delete; - stitched_morphology(stitched_morphology&&); + stitched_morphology(stitched_morphology&&) noexcept; arb::morphology morphology() const; region stitch(const std::string& id) const; diff --git a/arbor/include/arbor/s_expr.hpp b/arbor/include/arbor/s_expr.hpp index be3b86473a..1dec536606 100644 --- a/arbor/include/arbor/s_expr.hpp +++ b/arbor/include/arbor/s_expr.hpp @@ -69,7 +69,7 @@ struct ARB_ARBOR_API s_expr { // This value_wrapper is used to wrap the shared pointer template - struct value_wrapper{ + struct value_wrapper { using state_t = std::unique_ptr; state_t state; @@ -89,7 +89,7 @@ struct ARB_ARBOR_API s_expr { return *this; } - value_wrapper(value_wrapper&& other) = default; + value_wrapper(value_wrapper&& other) noexcept = default; friend std::ostream& operator<<(std::ostream& o, const value_wrapper& w) { return o << *w.state; @@ -210,21 +210,21 @@ struct ARB_ARBOR_API s_expr { s_expr(const s_expr& s) = default; s_expr() = default; - s_expr(token t): state(std::move(t)) {} + s_expr(const token& t): state(t) {} s_expr(s_expr l, s_expr r): state(pair_type(std::move(l), std::move(r))) {} s_expr& operator=(const s_expr& s) = default; - explicit s_expr(std::string s): - s_expr(token{{0,0}, tok::string, std::move(s)}) {} + explicit s_expr(const std::string& s): + s_expr(token{{0,0}, tok::string, s}) {} explicit s_expr(const char* s): s_expr(token{{0,0}, tok::string, s}) {} s_expr(double x): s_expr(token{{0,0}, tok::real, std::to_string(x)}) {} s_expr(int x): s_expr(token{{0,0}, tok::integer, std::to_string(x)}) {} - s_expr(symbol s): + s_expr(const symbol& s): s_expr(token{{0,0}, tok::symbol, s}) {} bool is_atom() const; diff --git a/arbor/include/arbor/simulation.hpp b/arbor/include/arbor/simulation.hpp index ba222fb431..9727e7aa12 100644 --- a/arbor/include/arbor/simulation.hpp +++ b/arbor/include/arbor/simulation.hpp @@ -35,13 +35,13 @@ class ARB_ARBOR_API simulation { simulation(const recipe& rec, context ctx = make_context(), - std::function balancer = + const std::function& balancer = [](auto& r, auto c) { return partition_load_balance(r, c); }, arb_seed_type seed = 0): simulation(rec, ctx, balancer(rec, ctx), seed) {} simulation(simulation const&) = delete; - simulation(simulation&&); + simulation(simulation&&) noexcept; static simulation_builder create(recipe const &); @@ -117,8 +117,8 @@ class ARB_ARBOR_API simulation_builder { return *this; } - simulation_builder& set_decomposition(domain_decomposition decomp) noexcept { - balancer_ = [decomp = std::move(decomp)](const recipe&, context) {return decomp; }; + simulation_builder& set_decomposition(const domain_decomposition& decomp) noexcept { + balancer_ = [decomp = decomp](const recipe&, context) {return decomp; }; return *this; } diff --git a/arbor/include/arbor/util/expected.hpp b/arbor/include/arbor/util/expected.hpp index 9b3f67dec6..410edaf108 100644 --- a/arbor/include/arbor/util/expected.hpp +++ b/arbor/include/arbor/util/expected.hpp @@ -72,7 +72,7 @@ struct unexpected { unexpected() = default; unexpected(const unexpected&) = default; - unexpected(unexpected&&) = default; + unexpected(unexpected&&) noexcept = default; // Emplace-style ctors. @@ -109,7 +109,7 @@ struct unexpected { unexpected& operator=(const unexpected& u) { value_ = u.value_; return *this; } - unexpected& operator=(unexpected&& u) { value_ = std::move(u.value_); return *this; } + unexpected& operator=(unexpected&& u) noexcept { value_ = std::move(u.value_); return *this; } template unexpected& operator=(const unexpected& u) { value_ = u.value_; return *this; } @@ -157,7 +157,7 @@ struct expected { expected() = default; expected(const expected&) = default; - expected(expected&&) = default; + expected(expected&&) noexcept = default; // Emplace-style ctors. @@ -424,7 +424,7 @@ struct expected { expected() = default; expected(const expected&) = default; - expected(expected&&) = default; + expected(expected&&) noexcept = default; // Emplace-style ctors. diff --git a/arbor/io/locked_ostream.cpp b/arbor/io/locked_ostream.cpp index f4948e395e..f4fd599078 100644 --- a/arbor/io/locked_ostream.cpp +++ b/arbor/io/locked_ostream.cpp @@ -59,11 +59,11 @@ locked_ostream::locked_ostream(std::streambuf *b): {} -locked_ostream::locked_ostream(locked_ostream&& other): - std::ostream(std::move(other)), // This moves other +locked_ostream::locked_ostream(locked_ostream&& other) noexcept: + std::ostream(std::move(other)), mex(std::move(other.mex)) { - set_rdbuf(other.rdbuf()); // ... and here we use it ... oh-oh + set_rdbuf(rdbuf()); other.set_rdbuf(nullptr); } diff --git a/arbor/io/locked_ostream.hpp b/arbor/io/locked_ostream.hpp index 07e9efd93a..e9dc256565 100644 --- a/arbor/io/locked_ostream.hpp +++ b/arbor/io/locked_ostream.hpp @@ -11,7 +11,7 @@ namespace io { struct locked_ostream: std::ostream { locked_ostream(std::streambuf *b); - locked_ostream(locked_ostream&& other); + locked_ostream(locked_ostream&& other) noexcept; ~locked_ostream() override; diff --git a/arbor/label_resolution.cpp b/arbor/label_resolution.cpp index f26604c6a2..2145efe6e8 100644 --- a/arbor/label_resolution.cpp +++ b/arbor/label_resolution.cpp @@ -30,7 +30,7 @@ void cell_label_range::add_label(cell_tag_type label, lid_range range) { if (sizes_.empty()) throw arbor_internal_error("adding label to cell_label_range without cell"); ++sizes_.back(); labels_.push_back(std::move(label)); - ranges_.push_back(std::move(range)); + ranges_.push_back(range); } void cell_label_range::append(cell_label_range other) { diff --git a/arbor/mechcat.cpp b/arbor/mechcat.cpp index 0d939bc467..7fde875dc9 100644 --- a/arbor/mechcat.cpp +++ b/arbor/mechcat.cpp @@ -527,8 +527,8 @@ std::vector mechanism_catalogue::mechanism_names() const { return state_->mechanism_names(); } -mechanism_catalogue::mechanism_catalogue(mechanism_catalogue&& other) = default; -mechanism_catalogue& mechanism_catalogue::operator=(mechanism_catalogue&& other) = default; +mechanism_catalogue::mechanism_catalogue(mechanism_catalogue&& other) noexcept = default; +mechanism_catalogue& mechanism_catalogue::operator=(mechanism_catalogue&& other) noexcept = default; mechanism_catalogue::mechanism_catalogue(const mechanism_catalogue& other): state_(new catalogue_state(*other.state_)) diff --git a/arbor/memory/array.hpp b/arbor/memory/array.hpp index f2dd9f7057..dbecf2c8d9 100644 --- a/arbor/memory/array.hpp +++ b/arbor/memory/array.hpp @@ -156,7 +156,7 @@ class array : } // move constructor - array(array&& other) { + array(array&& other) noexcept { #ifdef VERBOSE std::cerr << util::green("array(array&&)") << " " << util::type_printer::print() @@ -195,7 +195,7 @@ class array : return *this; } - array& operator = (array&& other) { + array& operator=(array&& other) noexcept { #ifdef VERBOSE std::cerr << util::green("array operator=(array&&)") << "\n this " << util::pretty_printer::print(*this) diff --git a/arbor/morph/cv_data.cpp b/arbor/morph/cv_data.cpp index cf3927e9ea..7777127824 100644 --- a/arbor/morph/cv_data.cpp +++ b/arbor/morph/cv_data.cpp @@ -88,7 +88,7 @@ cell_cv_data_impl::cell_cv_data_impl(const cable_cell& cell, const locset& lset) } util::sort(cables); - util::append(cv_cables, std::move(cables)); + util::append(cv_cables, cables); cv_cables_divs.push_back(cv_cables.size()); ++cv_index; } diff --git a/arbor/morph/label_dict.cpp b/arbor/morph/label_dict.cpp index ba0c4d83cd..46c9956f58 100644 --- a/arbor/morph/label_dict.cpp +++ b/arbor/morph/label_dict.cpp @@ -8,6 +8,7 @@ #include namespace arb { +using arb::locset; label_dict& label_dict::add_swc_tags() { set("soma", reg::tagged(1)); @@ -21,7 +22,7 @@ size_t label_dict::size() const { return locsets_.size() + regions_.size(); } -label_dict& label_dict::set(const std::string& name, arb::locset ls) { +label_dict &label_dict::set(const std::string &name, arb::locset ls) { if (regions_.count(name) || iexpressions_.count(name)) { throw label_type_mismatch(name); } diff --git a/arbor/morph/locset.cpp b/arbor/morph/locset.cpp index 28d3dff664..eaf9029a66 100644 --- a/arbor/morph/locset.cpp +++ b/arbor/morph/locset.cpp @@ -548,7 +548,6 @@ ARB_ARBOR_API locset uniform(arb::region reg, unsigned left, unsigned right, uin mlocation_list thingify_(const uniform_& u, const mprovider& p) { mlocation_list L; - auto morpho = p.morphology(); auto embed = p.embedding(); // Thingify the region and store relevant data diff --git a/arbor/morph/morphology.cpp b/arbor/morph/morphology.cpp index e36f341932..1bf32bf385 100644 --- a/arbor/morph/morphology.cpp +++ b/arbor/morph/morphology.cpp @@ -139,8 +139,8 @@ std::ostream& operator<<(std::ostream& o, const morphology_impl& m) { // morphology implementation // -morphology::morphology(segment_tree m): - impl_(std::make_shared(std::move(m))) +morphology::morphology(const segment_tree& m): + impl_(std::make_shared(m)) {} morphology::morphology(): @@ -436,6 +436,7 @@ ARB_ARBOR_API std::vector components(const morphology& m, const mextent } std::vector components; + components.reserve(component_cables.size()); for (auto& cl: component_cables) { components.emplace_back(std::move(cl)); } diff --git a/arbor/morph/region.cpp b/arbor/morph/region.cpp index fe43bcd9cc..becec36735 100644 --- a/arbor/morph/region.cpp +++ b/arbor/morph/region.cpp @@ -49,7 +49,7 @@ std::ostream& operator<<(std::ostream& o, const nil_&) { // Explicit cable section. struct cable_: region_tag { - explicit cable_(mcable c): cable(std::move(c)) {} + explicit cable_(mcable c): cable(c) {} mcable cable; }; @@ -346,7 +346,7 @@ std::ostream& operator<<(std::ostream& o, const proximal_interval_& d) { o << "(proximal-interval " << d.end << " " << d.distance << ")"; } -mextent radius_cmp(const mprovider& p, region r, double val, comp_op op) { +mextent radius_cmp(const mprovider& p, const region& r, double val, comp_op op) { const auto& e = p.embedding(); auto reg_extent = thingify(r, p); msize_t bid = mnpos; diff --git a/arbor/morph/stitch.cpp b/arbor/morph/stitch.cpp index 29b5cbbec9..5454369b1f 100644 --- a/arbor/morph/stitch.cpp +++ b/arbor/morph/stitch.cpp @@ -115,8 +115,8 @@ struct stitch_builder_impl { stitch_builder::stitch_builder(): impl_(new stitch_builder_impl) {} -stitch_builder::stitch_builder(stitch_builder&&) = default; -stitch_builder& stitch_builder::operator=(stitch_builder&&) = default; +stitch_builder::stitch_builder(stitch_builder&&) noexcept = default; +stitch_builder& stitch_builder::operator=(stitch_builder&&) noexcept = default; stitch_builder& stitch_builder::add(mstitch f, const std::string& parent_id, double along) { impl_->add(std::move(f), parent_id, along); @@ -166,7 +166,7 @@ stitched_morphology::stitched_morphology(const stitch_builder& builder): impl_(new stitched_morphology_impl(*builder.impl_)) {} -stitched_morphology::stitched_morphology(stitched_morphology&& other) = default; +stitched_morphology::stitched_morphology(stitched_morphology&& other) noexcept = default; arb::morphology stitched_morphology::morphology() const { return {impl_->stree}; diff --git a/arbor/partition_load_balance.cpp b/arbor/partition_load_balance.cpp index 80305bdcea..6cbc7deea4 100644 --- a/arbor/partition_load_balance.cpp +++ b/arbor/partition_load_balance.cpp @@ -172,6 +172,7 @@ ARB_ARBOR_API domain_decomposition partition_load_balance( }; std::vector kinds; + kinds.reserve(kind_lists.size()); for (auto l: kind_lists) { kinds.push_back(cell_kind(l.first)); } diff --git a/arbor/s_expr.cpp b/arbor/s_expr.cpp index 9e3135bf1b..0e21507ac8 100644 --- a/arbor/s_expr.cpp +++ b/arbor/s_expr.cpp @@ -483,7 +483,7 @@ s_expr parse(lexer& L) { else if (t.kind == tok::lparen) { auto e = parse(L); if (e.is_atom() && e.atom().kind==tok::error) return e; - *n = {std::move(e), {}}; + *n = {e, {}}; t = L.current(); } else { diff --git a/arbor/simulation.cpp b/arbor/simulation.cpp index fe32f853a3..a6ed83ad40 100644 --- a/arbor/simulation.cpp +++ b/arbor/simulation.cpp @@ -91,7 +91,7 @@ ARB_ARBOR_API void merge_cell_events( class simulation_state { public: - simulation_state(const recipe& rec, const domain_decomposition& decomp, context ctx, arb_seed_type seed); + simulation_state(const recipe& rec, const domain_decomposition& decomp, const context& ctx, arb_seed_type seed); void update(const connectivity& rec); @@ -193,7 +193,7 @@ class simulation_state { simulation_state::simulation_state( const recipe& rec, const domain_decomposition& decomp, - context ctx, + const context& ctx, arb_seed_type seed ): ctx_{ctx}, @@ -233,8 +233,8 @@ simulation_state::simulation_state( PL(); PE(init:simulation:resolvers); - source_resolution_map_ = label_resolution_map(std::move(global_sources)); - target_resolution_map_ = label_resolution_map(std::move(local_targets)); + source_resolution_map_ = label_resolution_map(global_sources); + target_resolution_map_ = label_resolution_map(local_targets); PL(); PE(init:simulation:comm); @@ -591,7 +591,7 @@ void simulation::inject_events(const cse_vector& events) { impl_->inject_events(events); } -simulation::simulation(simulation&&) = default; +simulation::simulation(simulation&&) noexcept = default; simulation::~simulation() = default; diff --git a/arbor/thread_private_spike_store.cpp b/arbor/thread_private_spike_store.cpp index e1645f037d..b791eac300 100644 --- a/arbor/thread_private_spike_store.cpp +++ b/arbor/thread_private_spike_store.cpp @@ -16,7 +16,7 @@ struct local_spike_store_type { local_spike_store_type(const task_system_handle& ts): buffers_(ts) {}; }; -thread_private_spike_store::thread_private_spike_store(thread_private_spike_store&& t): +thread_private_spike_store::thread_private_spike_store(thread_private_spike_store&& t) noexcept: impl_(std::move(t.impl_)) {} diff --git a/arbor/thread_private_spike_store.hpp b/arbor/thread_private_spike_store.hpp index d0006ef96a..e96600c470 100644 --- a/arbor/thread_private_spike_store.hpp +++ b/arbor/thread_private_spike_store.hpp @@ -24,7 +24,7 @@ public : thread_private_spike_store() = default; ~thread_private_spike_store(); - thread_private_spike_store(thread_private_spike_store&& t); + thread_private_spike_store(thread_private_spike_store&& t) noexcept; thread_private_spike_store(const task_system_handle& ts); /// Collate all of the individual buffers into a single vector of spikes. diff --git a/arbor/threading/threading.hpp b/arbor/threading/threading.hpp index 6783c09c52..cad194506d 100644 --- a/arbor/threading/threading.hpp +++ b/arbor/threading/threading.hpp @@ -246,14 +246,14 @@ class task_group { void set(std::exception_ptr ex) { error_.store(true, std::memory_order_relaxed); lock ex_lock{mutex_}; - exception_ = std::move(ex); + exception_ = ex; } // Clear exception state but return old state. // For consistency, this must only be called when there // are no tasks in flight that reference this exception state. std::exception_ptr reset() { - auto ex = std::move(exception_); + auto ex = exception_; error_.store(false, std::memory_order_relaxed); exception_ = nullptr; return ex; @@ -294,7 +294,7 @@ class task_group { exception_status_(ex) {} - wrap(wrap&& other): + wrap(wrap&& other) noexcept: f_(std::move(other.f_)), counter_(other.counter_), exception_status_(other.exception_status_) diff --git a/arbor/tree.cpp b/arbor/tree.cpp index 3ae342dff0..0ddee4563b 100644 --- a/arbor/tree.cpp +++ b/arbor/tree.cpp @@ -13,7 +13,7 @@ namespace arb { -tree::tree(std::vector parent_index) { +tree::tree(const std::vector& parent_index) { // validate the input if(!is_minimal_degree(parent_index)) { throw std::domain_error( diff --git a/arbor/tree.hpp b/arbor/tree.hpp index 137598318a..481df996cf 100644 --- a/arbor/tree.hpp +++ b/arbor/tree.hpp @@ -27,7 +27,7 @@ class ARB_ARBOR_API tree { /// Create the tree from a parent index that lists the parent segment /// of each segment in a cell tree. - tree(std::vector parent_index); + tree(const std::vector& parent_index); size_type num_children() const; diff --git a/arbor/util/counter.hpp b/arbor/util/counter.hpp index fc59c4a411..f5c4459d8f 100644 --- a/arbor/util/counter.hpp +++ b/arbor/util/counter.hpp @@ -21,7 +21,7 @@ struct counter { counter(V v): v_{v} {} counter(const counter&) = default; - counter(counter&&) = default; + counter(counter&&) noexcept = default; counter& operator++() { ++v_; @@ -85,7 +85,7 @@ struct counter { bool operator>(counter x) const { return v_>x.v_; } counter& operator=(const counter&) = default; - counter& operator=(counter&&) = default; + counter& operator=(counter&&) noexcept = default; private: V v_; diff --git a/arbor/util/filter.hpp b/arbor/util/filter.hpp index ad5801f0e4..bdc40a16e1 100644 --- a/arbor/util/filter.hpp +++ b/arbor/util/filter.hpp @@ -98,7 +98,7 @@ class filter_iterator { f_.construct(other.f_.cref()); } - filter_iterator(filter_iterator&& other): + filter_iterator(filter_iterator&& other) noexcept: inner_(std::move(other.inner_)), end_(std::move(other.end_)), ok_{other.ok_} @@ -106,7 +106,7 @@ class filter_iterator { f_.construct(std::move(other.f_.ref())); } - filter_iterator& operator=(filter_iterator&& other) { + filter_iterator& operator=(filter_iterator&& other) noexcept { if (this!=&other) { inner_ = std::move(other.inner_); end_ = std::move(other.end_); diff --git a/arbor/util/ordered_forest.hpp b/arbor/util/ordered_forest.hpp index b07b7e4960..5909f9ca60 100644 --- a/arbor/util/ordered_forest.hpp +++ b/arbor/util/ordered_forest.hpp @@ -452,7 +452,7 @@ class ordered_forest { return *this; } - ordered_forest& operator=(ordered_forest&& other) { + ordered_forest& operator=(ordered_forest&& other) noexcept { if (this==&other) return *this; delete_node(first_); diff --git a/arbor/util/piecewise.hpp b/arbor/util/piecewise.hpp index a6236daae4..37cb555ed9 100644 --- a/arbor/util/piecewise.hpp +++ b/arbor/util/piecewise.hpp @@ -121,7 +121,7 @@ struct pw_element { {} pw_element(const pw_element&) = default; - pw_element(pw_element&&) = default; + pw_element(pw_element&&) noexcept = default; operator X() const { return value; } pw_element& operator=(X x) { value = std::move(x); return *this; }; @@ -268,7 +268,7 @@ struct pw_elements { assign(vs, es); } - pw_elements(pw_elements&&) = default; + pw_elements(pw_elements&&) noexcept = default; pw_elements(const pw_elements&) = default; template @@ -276,7 +276,7 @@ struct pw_elements { vertex_(from.vertex_), value_(from.value_.begin(), from.value_.end()) {} - pw_elements& operator=(pw_elements&&) = default; + pw_elements& operator=(pw_elements&&) noexcept = default; pw_elements& operator=(const pw_elements&) = default; // Access: diff --git a/arbor/util/range.hpp b/arbor/util/range.hpp index 3a7257b7c1..a666282d50 100644 --- a/arbor/util/range.hpp +++ b/arbor/util/range.hpp @@ -52,7 +52,7 @@ struct range { range() = default; range(const range&) = default; - range(range&&) = default; + range(range&&) noexcept = default; template range(U1&& l, U2&& r): @@ -76,7 +76,7 @@ struct range { {} range& operator=(const range&) = default; - range& operator=(range&&) = default; + range& operator=(range&&) noexcept = default; template range& operator=(const range& other) { diff --git a/arbor/util/sentinel.hpp b/arbor/util/sentinel.hpp index 937f6feb94..bd4eaf4223 100644 --- a/arbor/util/sentinel.hpp +++ b/arbor/util/sentinel.hpp @@ -64,10 +64,10 @@ class sentinel_iterator { sentinel_iterator() = default; sentinel_iterator(const sentinel_iterator&) = default; - sentinel_iterator(sentinel_iterator&&) = default; + sentinel_iterator(sentinel_iterator&&) noexcept = default; sentinel_iterator& operator=(const sentinel_iterator&) = default; - sentinel_iterator& operator=(sentinel_iterator&&) = default; + sentinel_iterator& operator=(sentinel_iterator&&) noexcept = default; // forward and input iterator requirements diff --git a/arbor/util/transform.hpp b/arbor/util/transform.hpp index 26b4d5eb35..2be55960e0 100644 --- a/arbor/util/transform.hpp +++ b/arbor/util/transform.hpp @@ -59,11 +59,11 @@ class transform_iterator: public iterator_adaptor, I> { f_.construct(other.f_.cref()); } - transform_iterator(transform_iterator&& other): inner_(std::move(other.inner_)) { + transform_iterator(transform_iterator&& other) noexcept: inner_(std::move(other.inner_)) { f_.construct(std::move(other.f_.ref())); } - transform_iterator& operator=(transform_iterator&& other) { + transform_iterator& operator=(transform_iterator&& other) noexcept { if (this!=&other) { inner_ = std::move(other.inner_); f_.construct(std::move(other.f_.ref())); diff --git a/arborenv/arbenvexcept.cpp b/arborenv/arbenvexcept.cpp index add0cd419d..49131ad4fb 100644 --- a/arborenv/arbenvexcept.cpp +++ b/arborenv/arbenvexcept.cpp @@ -6,6 +6,7 @@ using namespace std::literals; namespace arbenv { +using std::string; invalid_env_value::invalid_env_value(const std::string& variable, const std::string& value): arborenv_exception("environment variable \""s + variable + R"(" has invalid value ")" + value + "\""s), @@ -20,8 +21,7 @@ no_such_gpu::no_such_gpu(int gpu_id): gpu_id(gpu_id) {} -gpu_uuid_error::gpu_uuid_error(std::string what): - arborenv_exception("error determining GPU uuids: "s+what) -{} +gpu_uuid_error::gpu_uuid_error(const string& what) + : arborenv_exception("error determining GPU uuids: "s + what) {} } // namespace arbenv diff --git a/arborenv/include/arborenv/arbenvexcept.hpp b/arborenv/include/arborenv/arbenvexcept.hpp index 49fba2c4dd..a0c433c311 100644 --- a/arborenv/include/arborenv/arbenvexcept.hpp +++ b/arborenv/include/arborenv/arbenvexcept.hpp @@ -33,7 +33,7 @@ struct ARB_SYMBOL_VISIBLE no_such_gpu: arborenv_exception { }; struct ARB_SYMBOL_VISIBLE gpu_uuid_error: arborenv_exception { - gpu_uuid_error(std::string what); + gpu_uuid_error(const std::string& what); }; } // namespace arbenv diff --git a/arborio/cableio.cpp b/arborio/cableio.cpp index 27c5718dbb..f7551d1724 100644 --- a/arborio/cableio.cpp +++ b/arborio/cableio.cpp @@ -148,15 +148,15 @@ s_expr mksexp(const label_dict& dict) { }; auto defs = slist(); for (auto& r: dict.locsets()) { - defs = s_expr(slist("locset-def"_symbol, s_expr(r.first), round_trip(r.second)), std::move(defs)); + defs = s_expr(slist("locset-def"_symbol, s_expr(r.first), round_trip(r.second)), defs); } for (auto& r: dict.regions()) { - defs = s_expr(slist("region-def"_symbol, s_expr(r.first), round_trip(r.second)), std::move(defs)); + defs = s_expr(slist("region-def"_symbol, s_expr(r.first), round_trip(r.second)), defs); } for (auto& r: dict.iexpressions()) { - defs = s_expr(slist("iexpr-def"_symbol, s_expr(r.first), round_trip(r.second)), std::move(defs)); + defs = s_expr(slist("iexpr-def"_symbol, s_expr(r.first), round_trip(r.second)), defs); } - return {"label-dict"_symbol, std::move(defs)}; + return {"label-dict"_symbol, defs}; } s_expr mksexp(const morphology& morph) { // s-expression representation of branch i in the morphology diff --git a/arborio/cv_policy_parse.cpp b/arborio/cv_policy_parse.cpp index 7e5bc2fe42..454ef52b7d 100644 --- a/arborio/cv_policy_parse.cpp +++ b/arborio/cv_policy_parse.cpp @@ -68,10 +68,10 @@ eval_map {{"default", make_call([] (const locset& l, const region& r) { return arb::cv_policy{arb::cv_policy_explicit(l, r) }; }, "'explicit' with two arguments (explicit (ls:locset) (reg:region))")}, {"join", - make_fold([](cv_policy l, cv_policy r) { return l + r; }, + make_fold([](const cv_policy& l, const cv_policy& r) { return l + r; }, "'join' with at least 2 arguments: (join cv_policy cv_policy ...)")}, {"replace", - make_fold([](cv_policy l, cv_policy r) { return l | r; }, + make_fold([](const cv_policy& l, const cv_policy& r) { return l | r; }, "'replace' with at least 2 arguments: (replace cv_policy cv_policy ...)")}, }; diff --git a/arborio/include/arborio/neurolucida.hpp b/arborio/include/arborio/neurolucida.hpp index a260c784ea..2498da9e70 100644 --- a/arborio/include/arborio/neurolucida.hpp +++ b/arborio/include/arborio/neurolucida.hpp @@ -48,7 +48,7 @@ ARB_ARBORIO_API asc_morphology parse_asc_string(const char* input); ARB_ARBORIO_API arb::segment_tree parse_asc_string_raw(const char* input); // Load asc morphology from file with name filename. -ARB_ARBORIO_API asc_morphology load_asc(std::string filename); -ARB_ARBORIO_API arb::segment_tree load_asc_raw(std::string filename); +ARB_ARBORIO_API asc_morphology load_asc(const std::string& filename); +ARB_ARBORIO_API arb::segment_tree load_asc_raw(const std::string& filename); } // namespace arborio diff --git a/arborio/include/arborio/neuroml.hpp b/arborio/include/arborio/neuroml.hpp index 7d889581b4..719b851924 100644 --- a/arborio/include/arborio/neuroml.hpp +++ b/arborio/include/arborio/neuroml.hpp @@ -112,10 +112,10 @@ struct ARB_ARBORIO_API neuroml { neuroml(); explicit neuroml(std::string nml_document); - neuroml(neuroml&&); + neuroml(neuroml&&) noexcept; neuroml(const neuroml&) = delete; - neuroml& operator=(neuroml&&); + neuroml& operator=(neuroml&&) noexcept; neuroml& operator=(const neuroml&) = delete; // Query top-level cells and (standalone) morphologies. diff --git a/arborio/neurolucida.cpp b/arborio/neurolucida.cpp index d8fbfbba24..7c8e37db82 100644 --- a/arborio/neurolucida.cpp +++ b/arborio/neurolucida.cpp @@ -786,7 +786,7 @@ ARB_ARBORIO_API asc_morphology parse_asc_string(const char* input) { } -inline std::string read_file(std::string filename) { +inline std::string read_file(const std::string& filename) { std::ifstream fid(filename); if (!fid.good()) { @@ -805,13 +805,13 @@ inline std::string read_file(std::string filename) { } -ARB_ARBORIO_API asc_morphology load_asc(std::string filename) { +ARB_ARBORIO_API asc_morphology load_asc(const std::string& filename) { std::string fstr = read_file(filename); return parse_asc_string(fstr.c_str()); } -ARB_ARBORIO_API arb::segment_tree load_asc_raw(std::string filename) { +ARB_ARBORIO_API arb::segment_tree load_asc_raw(const std::string& filename) { std::string fstr = read_file(filename); return parse_asc_string_raw(fstr.c_str()); } diff --git a/arborio/neuroml.cpp b/arborio/neuroml.cpp index 2b34ba3e99..7c1c0e66f9 100644 --- a/arborio/neuroml.cpp +++ b/arborio/neuroml.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -51,10 +52,10 @@ struct ARB_ARBORIO_API neuroml_impl { }; neuroml::neuroml(): impl_(new neuroml_impl) {} -neuroml::neuroml(std::string nml_document): impl_(new neuroml_impl{nml_document}) {} +neuroml::neuroml(std::string nml_document): impl_(new neuroml_impl{std::move(nml_document)}) {} -neuroml::neuroml(neuroml&&) = default; -neuroml& neuroml::operator=(neuroml&&) = default; +neuroml::neuroml(neuroml&&) noexcept = default; +neuroml& neuroml::operator=(neuroml&&) noexcept = default; neuroml::~neuroml() = default; diff --git a/arborio/xml.hpp b/arborio/xml.hpp index 2d0d3f3282..70fdc07da8 100644 --- a/arborio/xml.hpp +++ b/arborio/xml.hpp @@ -43,33 +43,37 @@ T get_attr(const xml_node& n, inline std::string xpath_escape(const std::string& x) { auto npos = std::string::npos; - if (x.find_first_of("'")==npos) { - return "'"+x+"'"; - } - else if (x.find_first_of("\"")==npos) { - return "\""+x+"\""; - } - else { - std::string r = "concat("; - std::string::size_type i = 0; - for (;;) { - auto j = x.find_first_of("'", i); - r += "'"; - r.append(x, i, j==npos? j: j-i); - r += "'"; - if (j==npos) break; - r += ",\""; - i = j+1; - j = x.find_first_not_of("'",i); - r.append(x, i, j==npos? j: j-i); - r += "\""; - if (j==npos) break; - r += ","; - i = j+1; - } - r += ")"; - return r; - } + + auto constexpr squote = '\''; + auto constexpr dquote = '\''; + + if (x.find_first_of(squote)==npos) { + return "'"+x+"'"; + } + else if (x.find_first_of(dquote)==npos) { + return "\""+x+"\""; + } + else { + std::string r = "concat("; + std::string::size_type i = 0; + for (;;) { + auto j = x.find_first_of(squote, i); + r += "'"; + r.append(x, i, j==npos? j: j-i); + r += "'"; + if (j==npos) break; + r += ",\""; + i = j+1; + j = x.find_first_not_of(squote, i); + r.append(x, i, j==npos? j: j-i); + r += "\""; + if (j==npos) break; + r += ","; + i = j+1; + } + r += ")"; + return r; + } } } diff --git a/lmorpho/lsystem.cpp b/lmorpho/lsystem.cpp index fc6ae0250d..e58700e557 100644 --- a/lmorpho/lsystem.cpp +++ b/lmorpho/lsystem.cpp @@ -351,7 +351,7 @@ std::vector generate_sections(double soma_radius, lsys_param P return sections; } -arb::segment_tree generate_morphology(const lsys_distribution_param& soma, std::vector Ps, lsys_generator &g) { +arb::segment_tree generate_morphology(const lsys_distribution_param& soma, const std::vector& Ps, lsys_generator &g) { double const soma_diameter = lsys_distribution(soma)(g); double const soma_radius = 0.5*soma_diameter; diff --git a/lmorpho/lsystem.hpp b/lmorpho/lsystem.hpp index 9dfc45353a..2200e5da6a 100644 --- a/lmorpho/lsystem.hpp +++ b/lmorpho/lsystem.hpp @@ -9,7 +9,7 @@ struct lsys_param; using lsys_generator = std::minstd_rand; struct lsys_distribution_param; -arb::segment_tree generate_morphology(const lsys_distribution_param& soma, std::vector Ps, lsys_generator& g); +arb::segment_tree generate_morphology(const lsys_distribution_param& soma, const std::vector& Ps, lsys_generator& g); // The distribution parameters used in the specification of the L-system parameters. // The distribution can be a constant, uniform over an interval, or truncated normal. From a10199b2e251bcc414f7e761befafb69d219975d Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Mon, 8 May 2023 10:03:48 +0200 Subject: [PATCH 05/17] Add clang-tidy config. --- .clang-tidy | 6 ++++++ arbor/io/locked_ostream.cpp | 1 - ext/.clang-tidy | 2 ++ modcc/.clang-tidy | 2 ++ test/.clang-tidy | 2 ++ 5 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .clang-tidy create mode 100644 ext/.clang-tidy create mode 100644 modcc/.clang-tidy create mode 100644 test/.clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..ee6ee457c2 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,6 @@ +Checks: "-*,modernize-*,-modernize-use-trailing-return-type,-modernize-concat-nested-namespaces,-modernize-avoid-c-arrays,-modernize-use-nodiscard,bugprone-*,-bugprone-exception-escape,-bugprone-macro-parentheses,-bugprone-easily-swappable-parameters,-bugprone-narrowing-conversions,misc-*,-misc-throw-by-value-catch-by-reference,-misc-no-recursion,-misc-non-private-member-variables-in-classes,-misc-const-correctness,-misc-confusable-identifiers,clang-analyzer-core-*,performance-*" +# WarningsAsErrors: "*" + +# IMPORTANT: Set HeaderFilterRegex as shown below. +# Do not set it to '.*', for example. +HeaderFilterRegex: "" diff --git a/arbor/io/locked_ostream.cpp b/arbor/io/locked_ostream.cpp index f4fd599078..a0066299bc 100644 --- a/arbor/io/locked_ostream.cpp +++ b/arbor/io/locked_ostream.cpp @@ -58,7 +58,6 @@ locked_ostream::locked_ostream(std::streambuf *b): mex(register_sbuf(b)) {} - locked_ostream::locked_ostream(locked_ostream&& other) noexcept: std::ostream(std::move(other)), mex(std::move(other.mex)) diff --git a/ext/.clang-tidy b/ext/.clang-tidy new file mode 100644 index 0000000000..2948278fe0 --- /dev/null +++ b/ext/.clang-tidy @@ -0,0 +1,2 @@ +# Disable all checks in this folder. +Checks: "-*" diff --git a/modcc/.clang-tidy b/modcc/.clang-tidy new file mode 100644 index 0000000000..2948278fe0 --- /dev/null +++ b/modcc/.clang-tidy @@ -0,0 +1,2 @@ +# Disable all checks in this folder. +Checks: "-*" diff --git a/test/.clang-tidy b/test/.clang-tidy new file mode 100644 index 0000000000..2948278fe0 --- /dev/null +++ b/test/.clang-tidy @@ -0,0 +1,2 @@ +# Disable all checks in this folder. +Checks: "-*" From 0d4a430a80c844ef3633068cb944f94099502b4c Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Mon, 8 May 2023 12:55:22 +0200 Subject: [PATCH 06/17] Fix path unintended override. --- arbor/mc_cell_group.cpp | 30 +++++++++++++++--------------- sup/include/sup/path.hpp | 8 ++++---- sup/path.cpp | 1 + test/unit/test_path.cpp | 4 ++-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/arbor/mc_cell_group.cpp b/arbor/mc_cell_group.cpp index 0f265f49e8..1f9788badb 100644 --- a/arbor/mc_cell_group.cpp +++ b/arbor/mc_cell_group.cpp @@ -151,20 +151,20 @@ void run_samples( fvm_probe_scratch& scratch) { constexpr sample_size_type n_raw_per_sample = 2; - sample_size_type n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; + auto n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; arb_assert((sc.end_offset-sc.begin_offset)==n_sample*n_raw_per_sample); auto& tmp = std::get>(scratch); tmp.clear(); sample_records.clear(); - for (sample_size_type j = 0; j #include diff --git a/test/unit/test_path.cpp b/test/unit/test_path.cpp index ac4c4e81f5..138912bca1 100644 --- a/test/unit/test_path.cpp +++ b/test/unit/test_path.cpp @@ -405,9 +405,9 @@ TEST(path, posix_directory_iterators) { bool found_dev_null = false; for (; it!=directory_iterator(); ++it) { - if (it->path()=="/dev/null") found_dev_null = true; + if (it->to_path()=="/dev/null") found_dev_null = true; - file_status st = symlink_status(it->path()); + file_status st = symlink_status(it->to_path()); // Check file type tests match up. EXPECT_EQ(it->is_block_file(), is_block_file(st)); From b65947f9668fee00d3bfbd884c9ca68ee384c40d Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Mon, 8 May 2023 14:42:47 +0200 Subject: [PATCH 07/17] Fix namespace. --- arbor/mc_cell_group.cpp | 3 +-- arbor/profile/profiler.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arbor/mc_cell_group.cpp b/arbor/mc_cell_group.cpp index 1f9788badb..005e60724e 100644 --- a/arbor/mc_cell_group.cpp +++ b/arbor/mc_cell_group.cpp @@ -178,8 +178,7 @@ void run_samples( const arb_value_type* raw_times, const arb_value_type* raw_samples, std::vector& sample_records, - fvm_probe_scratch& scratch) -{ + fvm_probe_scratch& scratch) { auto n_raw_per_sample = p.raw_handles.size(); auto n_sample = (sc.end_offset-sc.begin_offset)/n_raw_per_sample; arb_assert((sc.end_offset-sc.begin_offset)==n_sample*n_raw_per_sample); diff --git a/arbor/profile/profiler.cpp b/arbor/profile/profiler.cpp index eaffed8ff2..40cc77fb7d 100644 --- a/arbor/profile/profiler.cpp +++ b/arbor/profile/profiler.cpp @@ -239,7 +239,7 @@ profile profiler::results() const { p.counts = std::vector(nregions); for (auto& r: recorders_) { auto& accumulators = r.accumulators(); - for (auto i: make_span(0, accumulators.size())) { + for (auto i: util::make_span(0, accumulators.size())) { p.times[i] += accumulators[i].time; p.counts[i] += accumulators[i].count; } From 8ed17cefd9cf3ea9946084cdd167e7bad4f25b8d Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Tue, 9 May 2023 11:24:11 +0200 Subject: [PATCH 08/17] More namespaces! --- arbor/profile/profiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arbor/profile/profiler.cpp b/arbor/profile/profiler.cpp index 40cc77fb7d..b3d3f84fd3 100644 --- a/arbor/profile/profiler.cpp +++ b/arbor/profile/profiler.cpp @@ -275,10 +275,10 @@ profile_node make_profile_tree(const profile& p) { // Build a tree description of the regions and sub-regions in the profile. profile_node tree("root"); - for (auto idx: make_span(0, p.names.size())) { + for (auto idx: util::make_span(0, p.names.size())) { profile_node* node = &tree; const auto depth = names[idx].size(); - for (auto i: make_span(0, depth-1)) { + for (auto i: util::make_span(0, depth-1)) { auto& node_name = names[idx][i]; auto& kids = node->children; From 5525bd2b93c1da3fe8d083a498160030364efbe7 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:58:10 +0200 Subject: [PATCH 09/17] Warning-free on clang-tidy. --- CMakeLists.txt | 13 +++++++++++-- arbor/CMakeLists.txt | 4 +++- arbor/backends/multicore/shared_state.cpp | 12 ++++++------ arbor/cable_cell_group.cpp | 13 +++++++------ arbor/lif_cell_group.cpp | 2 +- arbor/simulation.cpp | 2 +- arbor/threading/threading.cpp | 12 ++++++------ arbor/threading/threading.hpp | 3 +-- lmorpho/CMakeLists.txt | 2 ++ mechanisms/BuildModules.cmake | 4 ++++ modcc/CMakeLists.txt | 4 ++++ test/unit/CMakeLists.txt | 14 ++++++-------- 12 files changed, 52 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb26e54b33..161b0b80e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,14 @@ mark_as_advanced(ARB_USE_HWLOC) option(BUILD_TESTING "build tests and benchmarks" ON) option(BUILD_DOCUMENTATION "build documentation" ON) +# Use C++ linter +option(ARB_CLANG_TIDY "lint C++ sources" OFF) + +if (ARB_CLANG_TIDY) + set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,clang-analyzer-*,) +endif () + + # Use externally built modcc? set(ARB_MODCC "" CACHE STRING "path to external modcc NMODL compiler") @@ -195,8 +203,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # Generate a .json file with full compilation command for each file. - -set(CMAKE_EXPORT_COMPILE_COMMANDS "YES") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Detect and deprecate xlC. @@ -648,6 +655,8 @@ add_subdirectory(sup) # modcc, libmodcc: add_subdirectory(modcc) +set_source_files_properties(DIRECTORY modcc + PROPERTIES SKIP_LINTING ON) # arbor, arbor-private-headers: add_subdirectory(arbor) diff --git a/arbor/CMakeLists.txt b/arbor/CMakeLists.txt index 29f5f32e6a..f84ac74a8f 100644 --- a/arbor/CMakeLists.txt +++ b/arbor/CMakeLists.txt @@ -128,7 +128,9 @@ set(_saved_CMAKE_MESSAGE_LOG_LEVEL ${CMAKE_MESSAGE_LOG_LEVEL}) set(CMAKE_MESSAGE_LOG_LEVEL WARNING) add_subdirectory(../mechanisms "${CMAKE_BINARY_DIR}/mechanisms") set(CMAKE_MESSAGE_LOG_LEVEL ${_saved_CMAKE_MESSAGE_LOG_LEVEL}) -set_source_files_properties(${arbor-builtin-mechanisms} DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTIES GENERATED TRUE) +set_source_files_properties(${arbor-builtin-mechanisms} + PROPERTIES GENERATED TRUE + SKIP_LINTING ON) if(ARB_WITH_CUDA_CLANG OR ARB_WITH_HIP_CLANG) set_source_files_properties(${arbor_sources} DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTIES LANGUAGE CXX) diff --git a/arbor/backends/multicore/shared_state.cpp b/arbor/backends/multicore/shared_state.cpp index 02975216f1..82f2ca0470 100644 --- a/arbor/backends/multicore/shared_state.cpp +++ b/arbor/backends/multicore/shared_state.cpp @@ -214,7 +214,6 @@ shared_state::shared_state(task_system_handle, // ignored in mc backend temperature_degC(n_cv_, pad(alignment)), diam_um(diam.begin(), diam.end(), pad(alignment)), time_since_spike(n_cell*static_cast(n_detector), pad(alignment)), - time_since_spike(n_cell*n_detector, pad(alignment)), src_to_spike(src_to_spike_.begin(), src_to_spike_.end(), pad(alignment)), cbprng_seed(cbprng_seed_), watcher{n_cv_, src_to_spike.data(), detector_info} @@ -258,14 +257,15 @@ std::pair shared_state::voltage_bounds() const { void shared_state::take_samples() { sample_events.mark(); - const auto& [begin, end] = sample_events.marked_events(); - if (begin == end) return; + auto [begin, end] = sample_events.marked_events(); + if (begin >= end) return; if (begin == nullptr || end == nullptr) throw arbor_internal_error{"Invalid sample stream state."}; // Null handles are explicitly permitted, and always give a sample of zero. - for (auto p = begin; p < end; ++p) { - auto off = p->offset; + for (; begin < end; ++begin) { + auto off = begin->offset; sample_time[off] = time; - sample_value[off] = p->handle ? *p->handle : 0; + sample_value[off] = 0; + if (begin->handle) sample_value[off] = *begin->handle; } } diff --git a/arbor/cable_cell_group.cpp b/arbor/cable_cell_group.cpp index e0acb984ae..d4a189f7b5 100644 --- a/arbor/cable_cell_group.cpp +++ b/arbor/cable_cell_group.cpp @@ -158,13 +158,13 @@ void run_samples( tmp.clear(); sample_records.clear(); - for (auto j = 0; j>(scratch); tmp.clear(); - tmp.reserve(static_cast(n_raw_per_sample*n_sample)); + tmp.reserve(static_cast(n_raw_per_sample)*n_sample); for (auto j = 0ul; j guard(sampler_mex_); auto probeset = probe_map_.keys(probeset_ids); if (!probeset.empty()) { - auto result = sampler_map_.insert({h, sampler_association{std::move(sched), - std::move(fn), - std::move(probeset)}}); + auto result [[maybe_unused]] = sampler_map_.insert({h, + sampler_association{std::move(sched), + std::move(fn), + std::move(probeset)}}); arb_assert(result.second); } } diff --git a/arbor/lif_cell_group.cpp b/arbor/lif_cell_group.cpp index fd154f2b1d..1f7597cca6 100644 --- a/arbor/lif_cell_group.cpp +++ b/arbor/lif_cell_group.cpp @@ -74,7 +74,7 @@ void lif_cell_group::add_sampler(sampler_association_handle h, auto assoc = arb::sampler_association{std::move(sched), std::move(fn), std::move(probeset)}; - auto result = samplers_.insert({h, std::move(assoc)}); + auto result [[maybe_unused]] = samplers_.insert({h, std::move(assoc)}); arb_assert(result.second); } diff --git a/arbor/simulation.cpp b/arbor/simulation.cpp index 821f9bf3b0..baea9d880d 100644 --- a/arbor/simulation.cpp +++ b/arbor/simulation.cpp @@ -621,7 +621,7 @@ void simulation::set_epoch_callback(epoch_function epoch_callback) { impl_->epoch_callback_ = std::move(epoch_callback); } -simulation::simulation(simulation&&) = default; +simulation::simulation(simulation&&) noexcept = default; simulation::~simulation() = default; diff --git a/arbor/threading/threading.cpp b/arbor/threading/threading.cpp index e10b50e6b4..4c1f51290f 100644 --- a/arbor/threading/threading.cpp +++ b/arbor/threading/threading.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -100,7 +99,7 @@ void task_system::run_tasks_loop(int index) { // Loop over the levels of priority starting from highest to lowest for (int pri = n_priority-1; pri>=0; --pri) { // Loop over the threads trying to pop a task of the requested priority. - for (unsigned n = 0; n=lowest_priority; --pri) { // Loop over the threads trying to pop a task of the requested priority. - for (unsigned n = 0; n != count_; n++) { + for (int n = 0; n != count_; n++) { if (auto ptsk = q_[(i + n) % count_].try_pop(pri)) { run(std::move(ptsk)); return; @@ -140,7 +139,7 @@ task_system::task_system(int nthreads, bool bind): count_(nthreads), bind_(bind), q_(nthreads) { - if (nthreads <= 0) throw std::runtime_error("Non-positive number of threads in thread pool"); + if (count_ <= 0) throw std::runtime_error("Non-positive number of threads in thread pool"); for (unsigned p = 0; p= n_priority) { run(std::move(ptsk)); } else { auto idx = index_[priority]++; - for (unsigned n = 0; n < count_; n++) { + for (int n = 0; n < count_; n++) { if (q_[(idx + n) % count_].try_push(ptsk)) return; } q_[idx % count_].push(std::move(ptsk)); diff --git a/arbor/threading/threading.hpp b/arbor/threading/threading.hpp index b52dc8479a..1b9a6d0ec3 100644 --- a/arbor/threading/threading.hpp +++ b/arbor/threading/threading.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -128,7 +127,7 @@ class ARB_ARBOR_API task_system { static constexpr unsigned nil = static_cast(-1); // Number of notification queues. - unsigned count_ = 1; + const int count_; // Attempt to bind threads? bool bind_ = false; // Worker threads. diff --git a/lmorpho/CMakeLists.txt b/lmorpho/CMakeLists.txt index 21262d16de..4febd2ee66 100644 --- a/lmorpho/CMakeLists.txt +++ b/lmorpho/CMakeLists.txt @@ -1,4 +1,6 @@ add_executable(lmorpho lmorpho.cpp lsystem.cpp lsys_models.cpp) +set_source_files_properties(lmorpho.cpp lsystem.cpp lsys_models.cpp + PROPERTIES SKIP_LINTING ON) target_link_libraries(lmorpho PRIVATE arbor arbor-sup ext-tinyopt arborio) diff --git a/mechanisms/BuildModules.cmake b/mechanisms/BuildModules.cmake index f28a9c1545..169ebc5a58 100644 --- a/mechanisms/BuildModules.cmake +++ b/mechanisms/BuildModules.cmake @@ -35,6 +35,8 @@ function("make_catalogue") list(APPEND catalogue_${MK_CAT_NAME}_source ${MK_CAT_OUT_DIR}/${mech}_gpu.cpp ${MK_CAT_OUT_DIR}/${mech}_gpu.cu) endif() endforeach() + set_source_files_properties(${catalogue_${MK_CAT_NAME}_source} + PROPERTIES SKIP_LINTING ON) add_custom_command(OUTPUT ${catalogue_${MK_CAT_NAME}_source} DEPENDS ${modcc} ${catalogue_${MK_CAT_NAME}_mods} @@ -80,6 +82,8 @@ function("make_catalogue_standalone") list(APPEND catalogue_${MK_CAT_NAME}_source ${MK_CAT_OUT_DIR}/${mech}_gpu.cpp ${MK_CAT_OUT_DIR}/${mech}_gpu.cu) endif() endforeach() + set_source_files_properties(${catalogue_${MK_CAT_NAME}_source} + PROPERTIES SKIP_LINTING ON) foreach(mech ${MK_CAT_CXX}) set(mk_cat_modcc_flags -r ${mech} ${mk_cat_modcc_flags}) diff --git a/modcc/CMakeLists.txt b/modcc/CMakeLists.txt index af691004b1..82c7747ce4 100644 --- a/modcc/CMakeLists.txt +++ b/modcc/CMakeLists.txt @@ -26,8 +26,12 @@ set(libmodcc_sources printer/infoprinter.cpp printer/printerutil.cpp ) +set_source_files_properties(${libmodcc_sources} + PROPERTIES SKIP_LINTING ON) set(modcc_sources modcc.cpp) +set_source_files_properties(${modcc_sources} + PROPERTIES SKIP_LINTING ON) add_library(libmodcc STATIC ${libmodcc_sources}) target_link_libraries(libmodcc PUBLIC arbor-public-headers) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index fc3f79e896..c968fd1967 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -183,14 +183,12 @@ add_executable(unit EXCLUDE_FROM_ALL ${unit_sources}) target_link_libraries(unit PRIVATE catalogue-testing) add_dependencies(tests unit) -make_catalogue_standalone( - NAME dummy - SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/dummy" - MOD dummy - CXX - CXX_FLAGS_TARGET ${ARB_CXX_FLAGS_TARGET_FULL} - VERBOSE ${ARB_CAT_VERBOSE}) - +make_catalogue_standalone(NAME dummy + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/dummy" + MOD dummy + CXX + CXX_FLAGS_TARGET ${ARB_CXX_FLAGS_TARGET_FULL} + VERBOSE ${ARB_CAT_VERBOSE}) target_link_libraries(dummy-catalogue PRIVATE arbor-private-deps) add_dependencies(unit dummy-catalogue) From 837b21a804e6e09baa5b08c84ce269ad8955e81a Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Thu, 12 Sep 2024 21:42:53 +0200 Subject: [PATCH 10/17] More updates, write .clang-tidy to all deps. --- .clang-tidy | 6 +++++- CMakeLists.txt | 14 +++++++++++--- arbor/backends/multicore/shared_state.cpp | 1 + arbor/network.cpp | 7 +++---- arbor/threading/threading.hpp | 1 - ext/.clang-tidy | 2 -- python/cells.cpp | 6 +++--- test/unit/CMakeLists.txt | 4 ++++ test/unit/test_diffusion.cpp | 2 +- 9 files changed, 28 insertions(+), 15 deletions(-) delete mode 100644 ext/.clang-tidy diff --git a/.clang-tidy b/.clang-tidy index ee6ee457c2..4c3f04ae41 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,8 @@ -Checks: "-*,modernize-*,-modernize-use-trailing-return-type,-modernize-concat-nested-namespaces,-modernize-avoid-c-arrays,-modernize-use-nodiscard,bugprone-*,-bugprone-exception-escape,-bugprone-macro-parentheses,-bugprone-easily-swappable-parameters,-bugprone-narrowing-conversions,misc-*,-misc-throw-by-value-catch-by-reference,-misc-no-recursion,-misc-non-private-member-variables-in-classes,-misc-const-correctness,-misc-confusable-identifiers,clang-analyzer-core-*,performance-*" +Checks: "-*,clang-analyzer-*,bugprone-*,-bugprone-exception-escape,-bugprone-macro-parentheses,-bugprone-easily-swappable-parameters,-bugprone-narrowing-conversions" +# ,modernize-*,-modernize-use-trailing-return-type,-modernize-concat-nested-namespaces,-modernize-avoid-c-arrays,-modernize-use-nodiscard +# ,misc-*,-misc-throw-by-value-catch-by-reference,-misc-no-recursion,-misc-non-private-member-variables-in-classes,-misc-const-correctness,-misc-confusable-identifiers +# + # WarningsAsErrors: "*" # IMPORTANT: Set HeaderFilterRegex as shown below. diff --git a/CMakeLists.txt b/CMakeLists.txt index 161b0b80e0..483449814d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,7 +80,7 @@ option(BUILD_DOCUMENTATION "build documentation" ON) option(ARB_CLANG_TIDY "lint C++ sources" OFF) if (ARB_CLANG_TIDY) - set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,clang-analyzer-*,) + set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--config-file=${CMAKE_SOURCE_DIR}/.clang-tidy") endif () @@ -314,6 +314,7 @@ CPMAddPackage(NAME random123 VERSION 1.14.0) if(random123_ADDED) target_include_directories(ext-random123 INTERFACE $) + write_file(${random123_SOURCE_DIR}/.clang-tidy "Checks: \"-*\"") else() find_package(Random123 REQUIRED) target_include_directories(ext-random123 INTERFACE ${RANDOM123_INCLUDE_DIR}) @@ -337,6 +338,7 @@ add_library(ext-pugixml INTERFACE) if(pugixml_ADDED) target_compile_definitions(ext-pugixml INTERFACE PUGIXML_HEADER_ONLY) target_include_directories(ext-pugixml INTERFACE $) + write_file(${pugixml_SOURCE_DIR}/.clang-tidy "Checks: \"-*\"") else() find_package(pugixml REQUIRED) target_link_libraries(ext-pugixml INTERFACE pugixml::pugixml) @@ -358,6 +360,12 @@ if (BUILD_TESTING) GIT_TAG release-1.12.1 VERSION 1.12.1 OPTIONS "INSTALL_GTEST OFF" "BUILD_GMOCK OFF") + if(benchmark_ADDED) + write_file(${benchmark_SOURCE_DIR}/.clang-tidy "Checks: \"-*\"") + endif() + if(googletest_ADDED) + write_file(${googletest_SOURCE_DIR}/.clang-tidy "Checks: \"-*\"") + endif() endif() CPMAddPackage(NAME units @@ -372,6 +380,7 @@ CPMAddPackage(NAME units add_library(ext-units INTERFACE) if(units_ADDED) target_link_libraries(ext-units INTERFACE units::units) + write_file(${units_SOURCE_DIR}/.clang-tidy "Checks: \"-*\"") else() find_package(units REQUIRED) target_link_libraries(ext-units INTERFACE units::units) @@ -387,6 +396,7 @@ CPMAddPackage(NAME tinyopt add_library(ext-tinyopt INTERFACE) if(tinyopt_ADDED) target_include_directories(ext-tinyopt INTERFACE $) + write_file(${tinyopt_SOURCE_DIR}/.clang-tidy "Checks: \"-*\"") else() message(FATAL_ERROR "Could not obtain tinyopt.") endif() @@ -655,8 +665,6 @@ add_subdirectory(sup) # modcc, libmodcc: add_subdirectory(modcc) -set_source_files_properties(DIRECTORY modcc - PROPERTIES SKIP_LINTING ON) # arbor, arbor-private-headers: add_subdirectory(arbor) diff --git a/arbor/backends/multicore/shared_state.cpp b/arbor/backends/multicore/shared_state.cpp index 82f2ca0470..3c79164c6c 100644 --- a/arbor/backends/multicore/shared_state.cpp +++ b/arbor/backends/multicore/shared_state.cpp @@ -213,6 +213,7 @@ shared_state::shared_state(task_system_handle, // ignored in mc backend init_voltage(init_membrane_potential.begin(), init_membrane_potential.end(), pad(alignment)), temperature_degC(n_cv_, pad(alignment)), diam_um(diam.begin(), diam.end(), pad(alignment)), + area_um2(area.begin(), area.end(), pad(alignment)), time_since_spike(n_cell*static_cast(n_detector), pad(alignment)), src_to_spike(src_to_spike_.begin(), src_to_spike_.end(), pad(alignment)), cbprng_seed(cbprng_seed_), diff --git a/arbor/network.cpp b/arbor/network.cpp index 1d6a08ffe8..4a8c77335b 100644 --- a/arbor/network.cpp +++ b/arbor/network.cpp @@ -661,10 +661,9 @@ struct network_selection_intersect_impl: public network_selection_impl { const auto d_right = right->max_distance(); if (d_left && d_right) return std::min(d_left.value(), d_right.value()); - if (d_left) return d_left.value(); - if (d_right) return d_right.value(); - - return std::nullopt; + if (d_left) return d_left; + if (d_right) return d_right; + return {}; } void initialize(const network_label_dict& dict) override { diff --git a/arbor/threading/threading.hpp b/arbor/threading/threading.hpp index 1b9a6d0ec3..abbc833350 100644 --- a/arbor/threading/threading.hpp +++ b/arbor/threading/threading.hpp @@ -123,7 +123,6 @@ class ARB_ARBOR_API notification_queue { }// namespace impl class ARB_ARBOR_API task_system { -private: static constexpr unsigned nil = static_cast(-1); // Number of notification queues. diff --git a/ext/.clang-tidy b/ext/.clang-tidy deleted file mode 100644 index 2948278fe0..0000000000 --- a/ext/.clang-tidy +++ /dev/null @@ -1,2 +0,0 @@ -# Disable all checks in this folder. -Checks: "-*" diff --git a/python/cells.cpp b/python/cells.cpp index 7300734312..7819ea1680 100644 --- a/python/cells.cpp +++ b/python/cells.cpp @@ -119,11 +119,11 @@ arb::cv_policy make_cv_policy_max_extent(double cv_length, const std::string& re // Allows rev_pot_method to be specified with string or mechanism_desc std::optional maybe_method(py::object method) { if (!method.is_none()) { - if (auto m=try_cast(method)) { - return *m; + if (auto m = try_cast(method)) { + return m; } else if (auto m=try_cast(method)) { - return *m; + return m; } else { throw std::runtime_error(util::pprintf("invalid rev_pot_method: {}", method)); diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index c968fd1967..5d93921809 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -179,6 +179,10 @@ if(ARB_WITH_CUDA_CLANG OR ARB_WITH_HIP_CLANG) set_source_files_properties(${unit_sources} PROPERTIES LANGUAGE CXX) endif() +set_source_files_properties(${unit_sources} + PROPERTIES SKIP_LINTING ON) + + add_executable(unit EXCLUDE_FROM_ALL ${unit_sources}) target_link_libraries(unit PRIVATE catalogue-testing) add_dependencies(tests unit) diff --git a/test/unit/test_diffusion.cpp b/test/unit/test_diffusion.cpp index 264450ce79..6439fbad16 100644 --- a/test/unit/test_diffusion.cpp +++ b/test/unit/test_diffusion.cpp @@ -42,7 +42,7 @@ struct linear: public recipe { // -----x----- segment_tree tree; auto p = mnpos; - p = tree.append(p, { -extent, 0, 0, diameter}, {extent, 0, 0, diameter}, 1); + tree.append(p, { -extent, 0, 0, diameter}, {extent, 0, 0, diameter}, 1); morph = {tree}; } From 8a21df78f544c7884b782f4c8fade5e55309031c Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Thu, 12 Sep 2024 21:50:45 +0200 Subject: [PATCH 11/17] Massage CMake. --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 483449814d..8d9ee12dbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -407,13 +407,15 @@ mark_as_advanced(FORCE googletest_DIR BUILD_GMOCK) mark_as_advanced(FORCE json_DIR JSON_CI JSON_BuildTests JSON_Diagnostics JSON_DisableEnumSerialization JSON_GlobalUDLs JSON_ImplicitConversions JSON_Install JSON_LegacyDiscardedValueComparison JSON_MultipleHeaders JSON_SystemInclude) mark_as_advanced(FORCE RANDOM123_INCLUDE_DIR) mark_as_advanced(FORCE pybind11_DIR PYBIND11_PYTHONLIBS_OVERWRITE PYBIND11_PYTHON_VERSION PYBIND11_FINDPYTHON PYBIND11_INSTALL PYBIND11_INTERNALS_VERSION PYBIND11_NOPYTHON PYBIND11_SIMPLE_GIL_MANAGEMENT PYBIND11_TEST) -mark_as_advanced(FORCE pugixml_DIR) +mark_as_advanced(FORCE pugixml_DIR FETCHCONTENT_SOURCE_DIR_PUGIXML FETCHCONTENT_UPDATES_DISCONNECTED_PUGIXML) mark_as_advanced(FORCE fmt_DIR) mark_as_advanced(FORCE units_DIR UNITS_BUILD_OBJECT_LIBRARY UNITS_BUILD_SHARED_LIBRARY UNITS_HEADER_ONLY UNITS_NAMESPACE) mark_as_advanced(FORCE tinyopt_DIR) mark_as_advanced(FORCE CXXFEATURECHECK_DEBUG) mark_as_advanced(FORCE CPM_DONT_CREATE_PACKAGE_LOCK CPM_DONT_UPDATE_MODULE_PATH CPM_DOWNLOAD_ALL CPM_INCLUDE_ALL_IN_PACKAGE_LOCK CPM_LOCAL_PACKAGES_ONLY CPM_SOURCE_CACHE CPM_USE_NAMED_CACHE_DIRECTORIES) mark_as_advanced(FORCE FETCHCONTENT_BASE_DIR FETCHCONTENT_FULLY_DISCONNECTED FETCHCONTENT_QUIET FETCHCONTENT_SOURCE_DIR_BENCHMARK FETCHCONTENT_SOURCE_DIR_GOOGLETEST FETCHCONTENT_SOURCE_DIR_JSON FETCHCONTENT_SOURCE_DIR_PYBIND11 FETCHCONTENT_SOURCE_DIR_RANDOM123 FETCHCONTENT_SOURCE_DIR_TINYOPT FETCHCONTENT_SOURCE_DIR_UNITS FETCHCONTENT_UPDATES_DISCONNECTED FETCHCONTENT_UPDATES_DISCONNECTED_BENCHMARK FETCHCONTENT_UPDATES_DISCONNECTED_GOOGLETEST FETCHCONTENT_UPDATES_DISCONNECTED_JSON FETCHCONTENT_UPDATES_DISCONNECTED_PYBIND11 FETCHCONTENT_UPDATES_DISCONNECTED_RANDOM123 FETCHCONTENT_UPDATES_DISCONNECTED_TINYOPT FETCHCONTENT_UPDATES_DISCONNECTED_UNITS) +mark_as_advanced(FORCE CMAKE_PDB_OUTPUT_DIRECTORY) +mark_as_advanced(FORCE PY_PYBIND11_STUBGEN PY_SVGWRITE) # Restore chattyness From f754c583df33c731f93e27558e96a2172f5dc2b4 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Thu, 12 Sep 2024 21:58:48 +0200 Subject: [PATCH 12/17] Add clang-tidy. --- .github/workflows/lint.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 518b0e9110..ac19931496 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,6 +12,8 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v4 + with: + submodules: recursive - name: Set up Python uses: actions/setup-python@v5 with: @@ -32,3 +34,12 @@ jobs: - name: Python analysis run: | flake8 . + - name: Install tools + run: | + sudo apt-get update + sudo apt-get install -y clang clang-tidy cmake ninja-build + - name: Lint + run: | + mkdir build + cd build + cmake .. -GNinja -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC -DARB_WITH_PYTHON=OFF -DARB_VECTORIZE=OFF -DARB_WITH_MPI=OFF -DARB_WITH_ASSERTIONS=ON -DARB_CLANG_TIDY=ON From 966017ed72bdf007b7a3051b8397b61ee3973ea2 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Fri, 13 Sep 2024 08:36:35 +0200 Subject: [PATCH 13/17] Set CC + CXX --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ac19931496..2ff73eeba3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -42,4 +42,4 @@ jobs: run: | mkdir build cd build - cmake .. -GNinja -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC -DARB_WITH_PYTHON=OFF -DARB_VECTORIZE=OFF -DARB_WITH_MPI=OFF -DARB_WITH_ASSERTIONS=ON -DARB_CLANG_TIDY=ON + cmake .. -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DARB_WITH_PYTHON=OFF -DARB_VECTORIZE=OFF -DARB_WITH_MPI=OFF -DARB_WITH_ASSERTIONS=ON -DARB_CLANG_TIDY=ON From 8055a878bac73ec7a2f0103406cfb3a82caa3f4f Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Fri, 13 Sep 2024 08:51:21 +0200 Subject: [PATCH 14/17] Add/fix docs. --- doc/contrib/pr.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/contrib/pr.rst b/doc/contrib/pr.rst index a490cb5d87..47fb5893c8 100644 --- a/doc/contrib/pr.rst +++ b/doc/contrib/pr.rst @@ -135,9 +135,9 @@ Each pull request is reviewed according to these guidelines: Pull requests will also be subject to a series of automated checks -- Python formatting will be checked using the `black `__ formatter -- Python files will be checked for common errors and code smells using `flake8 `__ -- C++ code will be run against a suite of sanitizers under the `clang `__ umbrella. The following checks are enabled +- Python formatting, common errors, and code smells will be checked by `ruff `__ +- C++ code will be statically checked by `clang-tidy `__. +- All executable code will be run against a suite of sanitizers under the `clang `__ umbrella. The following checks are enabled - `undefined behavior `__: under/overflow, null-deref, ... - `threads `__: data races and other threading related issues - `memory `__: illegal accesses, use-after-free, double free, ... From 6416de01b3737dca86a6b1f39eaa9d09bd0778b2 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Mon, 16 Sep 2024 14:38:51 +0200 Subject: [PATCH 15/17] Activate checker. --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bb5c1ab7ca..dd5e3d9a57 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -40,5 +40,5 @@ jobs: run: | mkdir build cd build - cmake .. -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DARB_WITH_PYTHON=OFF -DARB_VECTORIZE=OFF -DARB_WITH_MPI=OFF -DARB_WITH_ASSERTIONS=ON -DARB_CLANG_TIDY=ON + ninja From 09417c3224aecc975a00d905e804aaa1df8765f0 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Wed, 18 Sep 2024 07:28:20 +0200 Subject: [PATCH 16/17] Don't allow NULL even in error states. --- arborenv/default_env.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arborenv/default_env.cpp b/arborenv/default_env.cpp index f35b17308d..04d0609abb 100644 --- a/arborenv/default_env.cpp +++ b/arborenv/default_env.cpp @@ -23,9 +23,10 @@ ARB_ARBORENV_API unsigned long get_env_num_threads() { constexpr const char* env_var = "ARBENV_NUM_THREADS"; std::optional env_val = read_env_integer(env_var, throw_on_invalid); if (!env_val) return 0; - if (*env_val<1 || static_cast(*env_val)>std::numeric_limits::max()) { - throw invalid_env_value(env_var, std::getenv(env_var)); + std::string var = "???"; + if (auto v = std::getenv(env_var); v) var = v; + throw invalid_env_value(env_var, var); } return *env_val; } From bdd7da88296448845c4a9b211045d27aa8475017 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:48:49 +0200 Subject: [PATCH 17/17] trigger ci