From b09912476f8c5e8e9c89abd2b533421163767192 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 11 Apr 2023 15:26:28 +0200 Subject: [PATCH] Assignment operators should return non-"const" references (sonar). Also enfore C++ "rule-of-three". --- src/mc/api/strategy/BasicStrategy.hpp | 7 +++++-- src/mc/api/strategy/Strategy.hpp | 8 +++++--- src/mc/api/strategy/WaitStrategy.hpp | 9 ++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/mc/api/strategy/BasicStrategy.hpp b/src/mc/api/strategy/BasicStrategy.hpp index 93ebd6cc6c..80b7dc3b8c 100644 --- a/src/mc/api/strategy/BasicStrategy.hpp +++ b/src/mc/api/strategy/BasicStrategy.hpp @@ -11,9 +11,12 @@ namespace simgrid::mc { /** Basic MC guiding class which corresponds to no guide at all (random choice) */ class BasicStrategy : public Strategy { public: - void operator=(const BasicStrategy&) + BasicStrategy() = default; + ~BasicStrategy() = default; + BasicStrategy(const BasicStrategy&) = delete; + BasicStrategy& operator=(const BasicStrategy&) { /* nothing to copy over while cloning */ - return; + return *this; } std::pair next_transition() const override diff --git a/src/mc/api/strategy/Strategy.hpp b/src/mc/api/strategy/Strategy.hpp index ef5b87f37b..a530789624 100644 --- a/src/mc/api/strategy/Strategy.hpp +++ b/src/mc/api/strategy/Strategy.hpp @@ -17,10 +17,12 @@ protected: std::map actors_to_run_; public: - virtual ~Strategy() = default; - void operator=(const Strategy&) + Strategy() = default; + virtual ~Strategy() = default; + Strategy(const Strategy&) = delete; + Strategy& operator=(const Strategy&) { /* nothing to copy over while cloning */ - return; + return *this; } virtual std::pair next_transition() const = 0; diff --git a/src/mc/api/strategy/WaitStrategy.hpp b/src/mc/api/strategy/WaitStrategy.hpp index ae549129f4..182411ec4d 100644 --- a/src/mc/api/strategy/WaitStrategy.hpp +++ b/src/mc/api/strategy/WaitStrategy.hpp @@ -17,7 +17,14 @@ class WaitStrategy : public Strategy { bool taking_wait_ = false; public: - void operator=(const WaitStrategy& guide) { taken_wait_ = guide.taken_wait_; } + WaitStrategy() = default; + ~WaitStrategy() = default; + WaitStrategy(const BasicStrategy&) = delete; + WaitStrategy& operator=(const WaitStrategy& guide) + { + taken_wait_ = guide.taken_wait_; + return *this; + } bool is_transition_wait(Transition::Type type) const { -- 2.20.1