From 3d1b82ea258100f462174bf600a4aba73740224d Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Fri, 4 Sep 2020 14:52:52 +0300 Subject: [PATCH] sns: fixup a409dede vector will not copy when move ctor is marked noexcept remove the copy ctor 'trick', re-add dtor. explicitly do the thing we want (...clang-tidy would've shown this issue, something to do in the CI...) --- code/espurna/sensor.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/code/espurna/sensor.cpp b/code/espurna/sensor.cpp index 2816e8e3..7162cf5e 100644 --- a/code/espurna/sensor.cpp +++ b/code/espurna/sensor.cpp @@ -227,14 +227,18 @@ struct sensor_magnitude_t { } sensor_magnitude_t() = delete; - sensor_magnitude_t& operator=(const sensor_magnitude_t&) = default; - sensor_magnitude_t(const sensor_magnitude_t&) = default; - sensor_magnitude_t(sensor_magnitude_t&& other) { + + sensor_magnitude_t(const sensor_magnitude_t&) = delete; + sensor_magnitude_t(sensor_magnitude_t&& other) noexcept { *this = other; other.filter = nullptr; } + ~sensor_magnitude_t() { + delete filter; + } + sensor_magnitude_t(unsigned char slot, unsigned char index_local, unsigned char type, sensor::Unit units, BaseSensor* sensor); BaseSensor * sensor { nullptr }; // Sensor object @@ -259,6 +263,16 @@ struct sensor_magnitude_t { }; +static_assert( + std::is_nothrow_move_constructible::value, + "std::vector should be able to work with resize()" +); + +static_assert( + !std::is_copy_constructible::value, + "std::vector should only use move ctor" +); + unsigned char sensor_magnitude_t::_counts[MAGNITUDE_MAX] = {0}; namespace sensor {