From c8de1d1065c327e9c93c7389946cc2652c7d0f20 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 16 Mar 2022 21:37:55 +0100 Subject: [PATCH] Polymorphic base class destructor should be either public virtual or protected non-virtual. This is Sonar rule S1235 https://sonarcloud.io/organizations/simgrid/rules?open=cpp%3AS1235&rule_key=cpp%3AS1235 Some of the classes are simply marked "final" so that they can never become a polymorphic base class. --- include/simgrid/kernel/resource/NetworkModelIntf.hpp | 5 ++++- src/kernel/actor/CommObserver.hpp | 12 ++++++------ src/kernel/actor/SimcallObserver.hpp | 10 ++++++++-- src/kernel/actor/SynchroObserver.hpp | 8 ++++---- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/simgrid/kernel/resource/NetworkModelIntf.hpp b/include/simgrid/kernel/resource/NetworkModelIntf.hpp index b1dd2cf04a..ee1c446c59 100644 --- a/include/simgrid/kernel/resource/NetworkModelIntf.hpp +++ b/include/simgrid/kernel/resource/NetworkModelIntf.hpp @@ -19,6 +19,9 @@ namespace resource { * @brief Network Model interface class */ class XBT_PUBLIC NetworkModelIntf { +protected: + ~NetworkModelIntf() = default; + public: /** * @brief Callback to set the bandwidth and latency factors used in a communication @@ -47,4 +50,4 @@ public: } // namespace kernel } // namespace simgrid -#endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP */ \ No newline at end of file +#endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP */ diff --git a/src/kernel/actor/CommObserver.hpp b/src/kernel/actor/CommObserver.hpp index 2d86bc6b49..2358e5a08e 100644 --- a/src/kernel/actor/CommObserver.hpp +++ b/src/kernel/actor/CommObserver.hpp @@ -17,7 +17,7 @@ namespace simgrid { namespace kernel { namespace actor { -class ActivityTestSimcall : public ResultingSimcall { +class ActivityTestSimcall final : public ResultingSimcall { activity::ActivityImpl* const activity_; public: @@ -30,7 +30,7 @@ public: void serialize(std::stringstream& stream) const override; }; -class ActivityTestanySimcall : public ResultingSimcall { +class ActivityTestanySimcall final : public ResultingSimcall { const std::vector& activities_; std::vector indexes_; // indexes in activities_ pointing to ready activities (=whose test() is positive) int next_value_ = 0; @@ -46,7 +46,7 @@ public: int get_value() const { return next_value_; } }; -class ActivityWaitSimcall : public ResultingSimcall { +class ActivityWaitSimcall final : public ResultingSimcall { activity::ActivityImpl* activity_; const double timeout_; @@ -63,7 +63,7 @@ public: double get_timeout() const { return timeout_; } }; -class ActivityWaitanySimcall : public ResultingSimcall { +class ActivityWaitanySimcall final : public ResultingSimcall { const std::vector& activities_; std::vector indexes_; // indexes in activities_ pointing to ready activities (=whose test() is positive) const double timeout_; @@ -81,7 +81,7 @@ public: int get_value() const { return next_value_; } }; -class CommIsendSimcall : public SimcallObserver { +class CommIsendSimcall final : public SimcallObserver { activity::MailboxImpl* mbox_; double payload_size_; double rate_; @@ -134,7 +134,7 @@ public: auto const& get_copy_data_fun() const { return copy_data_fun_; } }; -class CommIrecvSimcall : public SimcallObserver { +class CommIrecvSimcall final : public SimcallObserver { activity::MailboxImpl* mbox_; unsigned char* dst_buff_; size_t* dst_buff_size_; diff --git a/src/kernel/actor/SimcallObserver.hpp b/src/kernel/actor/SimcallObserver.hpp index 7be562c9fe..56adb66920 100644 --- a/src/kernel/actor/SimcallObserver.hpp +++ b/src/kernel/actor/SimcallObserver.hpp @@ -19,6 +19,9 @@ namespace actor { class SimcallObserver { ActorImpl* const issuer_; +protected: + ~SimcallObserver() = default; + public: explicit SimcallObserver(ActorImpl* issuer) : issuer_(issuer) {} ActorImpl* get_issuer() const { return issuer_; } @@ -62,6 +65,9 @@ public: template class ResultingSimcall : public SimcallObserver { T result_; +protected: + ~ResultingSimcall() = default; + public: ResultingSimcall() = default; ResultingSimcall(ActorImpl* actor, T default_result) : SimcallObserver(actor), result_(default_result) {} @@ -69,7 +75,7 @@ public: T get_result() const { return result_; } }; -class RandomSimcall : public SimcallObserver { +class RandomSimcall final : public SimcallObserver { const int min_; const int max_; int next_value_ = 0; @@ -85,7 +91,7 @@ public: int get_value() const { return next_value_; } }; -class ConditionWaitSimcall : public ResultingSimcall { +class ConditionWaitSimcall final : public ResultingSimcall { activity::ConditionVariableImpl* const cond_; activity::MutexImpl* const mutex_; const double timeout_; diff --git a/src/kernel/actor/SynchroObserver.hpp b/src/kernel/actor/SynchroObserver.hpp index de283d1c08..15549bd0c7 100644 --- a/src/kernel/actor/SynchroObserver.hpp +++ b/src/kernel/actor/SynchroObserver.hpp @@ -18,7 +18,7 @@ namespace kernel { namespace actor { /* All the observers of Mutex transitions are very similar, so implement them all together in this class */ -class MutexObserver : public SimcallObserver { +class MutexObserver final : public SimcallObserver { mc::Transition::Type type_; activity::MutexImpl* const mutex_; @@ -32,7 +32,7 @@ public: }; /* This observer is used for SEM_LOCK and SEM_UNLOCK (only) */ -class SemaphoreObserver : public SimcallObserver { +class SemaphoreObserver final : public SimcallObserver { mc::Transition::Type type_; activity::SemaphoreImpl* const sem_; @@ -45,7 +45,7 @@ public: }; /* This observer is ued for SEM_WAIT, that is returning and needs the acquisition (in MC mode) */ -class SemaphoreAcquisitionObserver : public ResultingSimcall { +class SemaphoreAcquisitionObserver final : public ResultingSimcall { mc::Transition::Type type_; activity::SemAcquisitionImpl* const acquisition_; const double timeout_; @@ -61,7 +61,7 @@ public: }; /* This observer is ued for BARRIER_LOCK and BARRIER_WAIT. WAIT is returning and needs the acquisition */ -class BarrierObserver : public ResultingSimcall { +class BarrierObserver final : public ResultingSimcall { mc::Transition::Type type_; activity::BarrierImpl* const barrier_ = nullptr; activity::BarrierAcquisitionImpl* const acquisition_ = nullptr; -- 2.20.1