Skip to content

Commit f96dfce

Browse files
fix(core,meta,blocks): complete rule-of-five on flagged types (sonar cpp:S3624)
- on_scope_exit, IoThreadGuard: = delete copy and move (double-calling the scope-exit function / re-binding a ref member would be wrong) - MergeByIndex, Tensor (dynamic), GeneralRegistry, immutable, Graph, DynamicPort, StateMachine: add explicit ~T() = default to complete the rule-of-five that each type had already partly declared. - Writer, Reader (CircularBuffer): the copy-and-swap operator=(T tmp) was effectively move-only (copy ctor implicitly deleted by the user-declared move ctor). Make it explicit: take Writer&&/Reader&&, and = delete the copy ctor/assignment so the shape of the type is honest. Skipped (sonar false positives / already correct): indirect — already has ~indirect() = default; conditional copy ctor is intentional. Port — already has ~Port() = default; all 5 specials declared. InputSpan/OutputSpan — defaulted moves are correct; dtor uses a runtime instanceCount guard to avoid double-cleanup on moved-from. Signed-off-by: Ralph J. Steinhagen <r.steinhagen@gsi.de>
1 parent 059d967 commit f96dfce

10 files changed

Lines changed: 27 additions & 2 deletions

File tree

blocks/timing/include/gnuradio-4.0/GpsSource.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ for synchronising otherwise undisciplined SDRs using their PPS)">;
4444

4545
struct IoThreadGuard { // must be last member — destroyed first, ensuring IO thread exits before _serialPort/_parser
4646
bool& done;
47+
explicit IoThreadGuard(bool& done_) noexcept : done(done_) {}
48+
IoThreadGuard(const IoThreadGuard&) = delete;
49+
IoThreadGuard(IoThreadGuard&&) = delete;
50+
IoThreadGuard& operator=(const IoThreadGuard&) = delete;
51+
IoThreadGuard& operator=(IoThreadGuard&&) = delete;
4752
~IoThreadGuard() { gr::atomic_ref(done).wait(false); }
4853
};
4954
IoThreadGuard _ioGuard{_ioThreadDone};

core/include/gnuradio-4.0/BlockMerging.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class MergeByIndex : public Block<MergeByIndex<Left, OutId, Right, InId>> {
159159
MergeByIndex(const MergeByIndex& other) = delete;
160160
MergeByIndex& operator=(MergeByIndex& other) = delete;
161161
MergeByIndex& operator=(MergeByIndex&& other) = delete;
162+
~MergeByIndex() = default;
162163

163164
MergeByIndex(MergeByIndex&& other) noexcept(std::is_nothrow_move_constructible_v<Left> && std::is_nothrow_move_constructible_v<Right>) : _leftBlock(std::move(other._leftBlock)), _rightBlock(std::move(other._rightBlock)) {}
164165

core/include/gnuradio-4.0/BlockRegistry.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class GeneralRegistry {
6868
std::swap(_blockTypeHandlers, tmp._blockTypeHandlers);
6969
return *this;
7070
}
71+
~GeneralRegistry() = default;
7172

7273
#ifdef GR_ENABLE_BLOCK_REGISTRY
7374
template<BlockLike TBlock>

core/include/gnuradio-4.0/CircularBuffer.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,10 @@ class CircularBuffer {
465465
_offset(std::exchange(other._offset, 0)), //
466466
_internalSpan(std::exchange(other._internalSpan, std::span<T>{})) {};
467467

468-
Writer& operator=(Writer tmp) noexcept {
468+
Writer(const Writer&) = delete;
469+
Writer& operator=(const Writer&) = delete;
470+
471+
Writer& operator=(Writer&& tmp) noexcept {
469472
std::swap(_buffer, tmp._buffer);
470473
std::swap(_nRequestedSamplesToPublish, tmp._nRequestedSamplesToPublish);
471474
std::swap(_index, tmp._index);
@@ -719,7 +722,10 @@ class CircularBuffer {
719722
_nRequestedSamplesToConsume(other._nRequestedSamplesToConsume), //
720723
_nSamplesConsumed(other._nSamplesConsumed) {}
721724

722-
Reader& operator=(Reader tmp) noexcept {
725+
Reader(const Reader&) = delete;
726+
Reader& operator=(const Reader&) = delete;
727+
728+
Reader& operator=(Reader&& tmp) noexcept {
723729
std::swap(_readIndex, tmp._readIndex);
724730
std::swap(_readIndexCached, tmp._readIndexCached);
725731
std::swap(_buffer, tmp._buffer);

core/include/gnuradio-4.0/Graph.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ struct Graph : Block<Graph> {
361361
Graph(Graph&) = delete; // there can be only one owner of Graph
362362
Graph& operator=(Graph&) = delete; // there can be only one owner of Graph
363363
Graph& operator=(Graph&& other) = delete;
364+
~Graph() = default;
364365

365366
[[nodiscard]] std::span<const std::shared_ptr<BlockModel>> blocks() const noexcept { return _blocks; }
366367
[[nodiscard]] std::span<std::shared_ptr<BlockModel>> blocks() noexcept { return _blocks; }

core/include/gnuradio-4.0/LifeCycle.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ class StateMachine {
191191
}
192192

193193
StateMachine(StateMachine&& other) noexcept { *this = std::move(other); }
194+
~StateMachine() = default;
195+
StateMachine(const StateMachine&) = delete;
196+
StateMachine& operator=(const StateMachine&) = delete;
194197

195198
StateMachine& operator=(StateMachine&& other) noexcept {
196199
// _other's state is put in STOPPED, so that a moved-from ~Block() becomes a no-op

core/include/gnuradio-4.0/Port.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@ class DynamicPort {
11971197

11981198
DynamicPort(const DynamicPort& arg) = delete;
11991199
DynamicPort& operator=(const DynamicPort& arg) = delete;
1200+
~DynamicPort() = default;
12001201

12011202
DynamicPort(DynamicPort&& other) noexcept : priority(other.priority), min_samples(other.min_samples), max_samples(other.max_samples), metaInfo(other.metaInfo), _accessor(std::move(other._accessor)) {}
12021203
auto& operator=(DynamicPort&& other) noexcept {

core/include/gnuradio-4.0/Tensor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ struct Tensor<T, Ex...> : TensorBase<T, true, Ex...> { // fully or partially dyn
10511051
using base_t::strides;
10521052

10531053
Tensor(Tensor&& other) noexcept = default;
1054+
~Tensor() = default;
10541055
explicit Tensor(const T& v, std::pmr::memory_resource* mr = std::pmr::get_default_resource()) {
10551056
base_t::_data = make_container(mr);
10561057
base_t::fill(v);

meta/include/gnuradio-4.0/meta/immutable.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class immutable {
3232
immutable<T>& operator=(const immutable<T>& other) = delete;
3333
immutable<T>& operator=(immutable<T>&& other) = delete;
3434

35+
~immutable() = default;
36+
3537
const T& value() const { return _value; }
3638

3739
operator const T&() const { return _value; }

meta/include/gnuradio-4.0/meta/utils.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,10 @@ template<typename Fn>
886886
struct on_scope_exit {
887887
Fn function;
888888
on_scope_exit(Fn fn) : function(std::move(fn)) {}
889+
on_scope_exit(const on_scope_exit&) = delete;
890+
on_scope_exit(on_scope_exit&&) = delete;
891+
on_scope_exit& operator=(const on_scope_exit&) = delete;
892+
on_scope_exit& operator=(on_scope_exit&&) = delete;
889893
~on_scope_exit() { function(); }
890894
};
891895

0 commit comments

Comments
 (0)