Browse Source

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...)
mcspr-patch-1
Maxim Prokhorov 4 years ago
parent
commit
3d1b82ea25
1 changed files with 17 additions and 3 deletions
  1. +17
    -3
      code/espurna/sensor.cpp

+ 17
- 3
code/espurna/sensor.cpp View File

@ -227,14 +227,18 @@ struct sensor_magnitude_t {
} }
sensor_magnitude_t() = delete; sensor_magnitude_t() = delete;
sensor_magnitude_t& operator=(const sensor_magnitude_t&) = default; 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; *this = other;
other.filter = nullptr; 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); sensor_magnitude_t(unsigned char slot, unsigned char index_local, unsigned char type, sensor::Unit units, BaseSensor* sensor);
BaseSensor * sensor { nullptr }; // Sensor object BaseSensor * sensor { nullptr }; // Sensor object
@ -259,6 +263,16 @@ struct sensor_magnitude_t {
}; };
static_assert(
std::is_nothrow_move_constructible<sensor_magnitude_t>::value,
"std::vector<sensor_magnitude_t> should be able to work with resize()"
);
static_assert(
!std::is_copy_constructible<sensor_magnitude_t>::value,
"std::vector<sensor_magnitude_t> should only use move ctor"
);
unsigned char sensor_magnitude_t::_counts[MAGNITUDE_MAX] = {0}; unsigned char sensor_magnitude_t::_counts[MAGNITUDE_MAX] = {0};
namespace sensor { namespace sensor {


Loading…
Cancel
Save