From: Ciro Santilli Date: Tue, 24 Nov 2020 13:22:03 +0000 (+0000) Subject: sim: make ProbeListener satisfy the rule of five with deleted X-Git-Tag: develop-gem5-snapshot~408 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=da7ce7214497d74d83c5d2923081e584c70ccb05;p=gem5.git sim: make ProbeListener satisfy the rule of five with deleted Since this class has a custom destructor ~ProbeListener(), it should also generally have the 4 other methods defined, otherwise calling those methods lead to subtle failures. In this specific case, the ProbeManager *const manager; field stores a pointer back to the ProbeListener object at: ProbeListener::ProbeListener { manager->addListener(name, *this); which gets unregistered by the destructor: ProbeListener::~ProbeListener() manager->removeListener(name, *this); and because the default copy does not re-register anything, it leads to unregistration. Therefore, a copy constructor would need the manager to support multiple identical listeners, or at least refcount them, which would be overkill. The two move operations would be more feasible, as we could make them unregister the old ProbeListener address and then re-register the new one, but that is not very efficient, so we just delete them as well. A consequence of not implementing the move methods is that it is impossible to store ProbeListener inside an std::vector. since objects inside std::vector may need to be moved in memory when the vector resizes, and therefore need to be movable. The alternative is to use an std::vector of std::unique_ptr instead. Change-Id: I8dc0157665391f86e2ca81d144bc6a42e9312d6c Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/37977 Reviewed-by: Andreas Sandberg Maintainer: Andreas Sandberg Tested-by: kokoro --- diff --git a/src/sim/probe/probe.hh b/src/sim/probe/probe.hh index 97edf0bd7..57132fc8b 100644 --- a/src/sim/probe/probe.hh +++ b/src/sim/probe/probe.hh @@ -119,6 +119,10 @@ class ProbeListener public: ProbeListener(ProbeManager *manager, const std::string &name); virtual ~ProbeListener(); + ProbeListener(const ProbeListener& other) = delete; + ProbeListener& operator=(const ProbeListener& other) = delete; + ProbeListener(ProbeListener&& other) noexcept = delete; + ProbeListener& operator=(ProbeListener&& other) noexcept = delete; protected: ProbeManager *const manager;