From 39ffec281af577c766c619d568f7a7051d108b00 Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Wed, 25 Apr 2018 09:30:56 +0200 Subject: misc: mark constructors as explicit Set 218 constructors as explicit to avoid implicit usage. Fix for cppcheck warning: Class has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided. For more information check: https://www.codeproject.com/Articles/28663/Explicit-Constructor-in-C Signed-off-by: Danny Al-Gaaf --- src/msg/async/dpdk/EventDPDK.h | 2 +- src/msg/async/dpdk/Packet.h | 8 ++++---- src/msg/async/dpdk/UserspaceEvent.h | 2 +- src/msg/async/dpdk/ethernet.h | 4 ++-- src/msg/async/dpdk/net.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/msg/async/dpdk') diff --git a/src/msg/async/dpdk/EventDPDK.h b/src/msg/async/dpdk/EventDPDK.h index 3e2aeb0e39e..9744b31a09f 100644 --- a/src/msg/async/dpdk/EventDPDK.h +++ b/src/msg/async/dpdk/EventDPDK.h @@ -26,7 +26,7 @@ class DPDKDriver : public EventDriver { public: UserspaceEventManager manager; - DPDKDriver(CephContext *c): cct(c), manager(c) {} + explicit DPDKDriver(CephContext *c): cct(c), manager(c) {} virtual ~DPDKDriver() { } int init(EventCenter *c, int nevent) override; diff --git a/src/msg/async/dpdk/Packet.h b/src/msg/async/dpdk/Packet.h index 3daab3172d0..b22492db865 100644 --- a/src/msg/async/dpdk/Packet.h +++ b/src/msg/async/dpdk/Packet.h @@ -104,7 +104,7 @@ class Packet { fragment frags[]; - impl(size_t nr_frags = default_nr_frags); + explicit impl(size_t nr_frags = default_nr_frags); impl(const impl&) = delete; impl(fragment frag, size_t nr_frags = default_nr_frags); @@ -180,7 +180,7 @@ class Packet { to->frags[0].base); } }; - Packet(std::unique_ptr&& impl) : _impl(std::move(impl)) {} + explicit Packet(std::unique_ptr&& impl) : _impl(std::move(impl)) {} std::unique_ptr _impl; public: static Packet from_static_data(const char* data, size_t len) { @@ -190,13 +190,13 @@ public: // build empty Packet Packet(); // build empty Packet with nr_frags allocated - Packet(size_t nr_frags); + explicit Packet(size_t nr_frags); // move existing Packet Packet(Packet&& x) noexcept; // copy data into Packet Packet(const char* data, size_t len); // copy data into Packet - Packet(fragment frag); + explicit Packet(fragment frag); // zero-copy single fragment Packet(fragment frag, deleter del); // zero-copy multiple fragments diff --git a/src/msg/async/dpdk/UserspaceEvent.h b/src/msg/async/dpdk/UserspaceEvent.h index 1a725a667d8..75f3abf78ab 100644 --- a/src/msg/async/dpdk/UserspaceEvent.h +++ b/src/msg/async/dpdk/UserspaceEvent.h @@ -46,7 +46,7 @@ class UserspaceEventManager { std::list unused_fds; public: - UserspaceEventManager(CephContext *c): cct(c) { + explicit UserspaceEventManager(CephContext *c): cct(c) { waiting_fds.resize(1024); } diff --git a/src/msg/async/dpdk/ethernet.h b/src/msg/async/dpdk/ethernet.h index 17546d73a10..4efd9416cf2 100644 --- a/src/msg/async/dpdk/ethernet.h +++ b/src/msg/async/dpdk/ethernet.h @@ -32,11 +32,11 @@ struct ethernet_address { ethernet_address() {} - ethernet_address(const uint8_t *eaddr) { + explicit ethernet_address(const uint8_t *eaddr) { std::copy(eaddr, eaddr + 6, mac.begin()); } - ethernet_address(std::initializer_list eaddr) { + explicit ethernet_address(std::initializer_list eaddr) { assert(eaddr.size() == mac.size()); std::copy(eaddr.begin(), eaddr.end(), mac.begin()); } diff --git a/src/msg/async/dpdk/net.h b/src/msg/async/dpdk/net.h index c48815b8d33..53ef473cf95 100644 --- a/src/msg/async/dpdk/net.h +++ b/src/msg/async/dpdk/net.h @@ -105,7 +105,7 @@ class interface { stream packet_stream; std::function forward; bool ready() { return packet_stream.started(); } - l3_rx_stream(std::function&& fw) : forward(fw) {} + explicit l3_rx_stream(std::function&& fw) : forward(fw) {} }; std::unordered_map _proto_map; std::shared_ptr _dev; -- cgit v1.2.3