From e00114b3f157d3da5a610d10345a210c9a46eca5 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 20 Mar 2019 11:23:57 -0700 Subject: [PATCH] [style] mark single-arg constructors as explicit (#3705) Avoids unintentional implicit conversions. --- src/cli/cli.cpp | 2 +- src/cli/cli.hpp | 2 +- src/cli/cli_coap.hpp | 2 +- src/cli/cli_coap_secure.hpp | 2 +- src/cli/cli_console.hpp | 2 +- src/cli/cli_dataset.hpp | 2 +- src/cli/cli_server.hpp | 2 +- src/cli/cli_uart.hpp | 2 +- src/cli/cli_udp.hpp | 2 +- src/core/api/link_api.cpp | 3 ++- src/core/api/thread_api.cpp | 4 ++-- src/core/coap/coap.hpp | 2 +- src/core/common/crc16.hpp | 2 +- src/core/common/locator.hpp | 4 ++-- src/core/common/message.hpp | 2 +- src/core/common/settings.hpp | 2 +- src/core/common/string.hpp | 2 +- src/core/common/timer.hpp | 4 ++-- src/core/mac/channel_mask.hpp | 2 +- src/core/mac/mac.cpp | 2 +- src/core/meshcop/dataset.hpp | 2 +- src/core/meshcop/joiner.cpp | 4 ++-- src/core/net/dns_client.hpp | 2 +- src/core/net/sntp_client.hpp | 2 +- src/core/thread/announce_sender.cpp | 2 +- src/core/thread/network_data.hpp | 2 +- src/core/thread/router_table.hpp | 6 +++--- src/core/utils/channel_monitor.hpp | 2 +- src/ncp/ncp_base.hpp | 2 +- src/ncp/ncp_spi.hpp | 4 ++-- src/ncp/ncp_uart.hpp | 2 +- src/ncp/spinel_encoder.hpp | 2 +- 32 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 4faaf2775..5cca37200 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -263,7 +263,7 @@ template class otPtr T *ptr; public: - otPtr(T *_ptr) + explicit otPtr(T *_ptr) : ptr(_ptr) { } diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index a7e6aa49c..fc8960a1b 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -110,7 +110,7 @@ public: * * @param[in] aInstance The OpenThread instance structure. */ - Interpreter(Instance *aInstance); + explicit Interpreter(Instance *aInstance); /** * This method interprets a CLI command. diff --git a/src/cli/cli_coap.hpp b/src/cli/cli_coap.hpp index a469aa41a..0728222c8 100644 --- a/src/cli/cli_coap.hpp +++ b/src/cli/cli_coap.hpp @@ -58,7 +58,7 @@ public: * @param[in] aInterpreter The CLI interpreter. * */ - Coap(Interpreter &aInterpreter); + explicit Coap(Interpreter &aInterpreter); /** * This method interprets a list of CLI arguments. diff --git a/src/cli/cli_coap_secure.hpp b/src/cli/cli_coap_secure.hpp index c723d0360..0f0d12be9 100644 --- a/src/cli/cli_coap_secure.hpp +++ b/src/cli/cli_coap_secure.hpp @@ -64,7 +64,7 @@ public: * @param[in] aInterpreter The CLI interpreter. * */ - CoapSecure(Interpreter &aInterpreter); + explicit CoapSecure(Interpreter &aInterpreter); /** * This method interprets a list of CLI arguments. diff --git a/src/cli/cli_console.hpp b/src/cli/cli_console.hpp index aa12840f5..80587c9c8 100644 --- a/src/cli/cli_console.hpp +++ b/src/cli/cli_console.hpp @@ -57,7 +57,7 @@ public: * @param[in] aInstance The OpenThread instance structure. * */ - Console(Instance *aInstance); + explicit Console(Instance *aInstance); /** * This method delivers raw characters to the client. diff --git a/src/cli/cli_dataset.hpp b/src/cli/cli_dataset.hpp index f1b8d0e01..436d0485b 100644 --- a/src/cli/cli_dataset.hpp +++ b/src/cli/cli_dataset.hpp @@ -52,7 +52,7 @@ class Interpreter; class Dataset { public: - Dataset(Interpreter &aInterpreter) + explicit Dataset(Interpreter &aInterpreter) : mInterpreter(aInterpreter) { } diff --git a/src/cli/cli_server.hpp b/src/cli/cli_server.hpp index bc1297ab8..0744aa61f 100644 --- a/src/cli/cli_server.hpp +++ b/src/cli/cli_server.hpp @@ -48,7 +48,7 @@ namespace Cli { class Server { public: - Server(Instance *aInstance) + explicit Server(Instance *aInstance) : mInterpreter(aInstance) { } diff --git a/src/cli/cli_uart.hpp b/src/cli/cli_uart.hpp index ccf85add2..f5a7b747a 100644 --- a/src/cli/cli_uart.hpp +++ b/src/cli/cli_uart.hpp @@ -57,7 +57,7 @@ public: * @param[in] aInstance The OpenThread instance structure. * */ - Uart(Instance *aInstance); + explicit Uart(Instance *aInstance); /** * This method delivers raw characters to the client. diff --git a/src/cli/cli_udp.hpp b/src/cli/cli_udp.hpp index cb18f38d1..eeb1f33ad 100644 --- a/src/cli/cli_udp.hpp +++ b/src/cli/cli_udp.hpp @@ -56,7 +56,7 @@ public: * @param[in] aInterpreter The CLI interpreter. * */ - UdpExample(Interpreter &aInterpreter); + explicit UdpExample(Interpreter &aInterpreter); /** * This method interprets a list of CLI arguments. diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index f55e3a762..ae02f99f8 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -36,6 +36,7 @@ #include #include "common/instance.hpp" +#include "mac/mac.hpp" #include "phy/phy.hpp" using namespace ot; @@ -101,7 +102,7 @@ otError otLinkSetSupportedChannelMask(otInstance *aInstance, uint32_t aChannelMa VerifyOrExit(instance.GetThreadNetif().GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE); - instance.GetThreadNetif().GetMac().SetSupportedChannelMask(aChannelMask); + instance.GetThreadNetif().GetMac().SetSupportedChannelMask(static_cast(aChannelMask)); exit: return error; diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index bba3cba99..5a343ef68 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -507,8 +507,8 @@ otError otThreadDiscover(otInstance * aInstance, { Instance &instance = *static_cast(aInstance); - return instance.GetThreadNetif().GetMle().Discover(aScanChannels, aPanId, aJoiner, aEnableEui64Filtering, aCallback, - aCallbackContext); + return instance.GetThreadNetif().GetMle().Discover(static_cast(aScanChannels), aPanId, aJoiner, + aEnableEui64Filtering, aCallback, aCallbackContext); } bool otThreadIsDiscoverInProgress(otInstance *aInstance) diff --git a/src/core/coap/coap.hpp b/src/core/coap/coap.hpp index 741b213c5..6d95af45a 100644 --- a/src/core/coap/coap.hpp +++ b/src/core/coap/coap.hpp @@ -267,7 +267,7 @@ public: * @param[in] aMessageInfo The message info containing source endpoint identification. * */ - EnqueuedResponseHeader(const Ip6::MessageInfo &aMessageInfo) + explicit EnqueuedResponseHeader(const Ip6::MessageInfo &aMessageInfo) : mDequeueTime(TimerMilli::GetNow() + TimerMilli::SecToMsec(kExchangeLifetime)) , mMessageInfo(aMessageInfo) { diff --git a/src/core/common/crc16.hpp b/src/core/common/crc16.hpp index 2d2ef35dd..fa0a3f199 100644 --- a/src/core/common/crc16.hpp +++ b/src/core/common/crc16.hpp @@ -59,7 +59,7 @@ public: * @param[in] aPolynomial The polynomial value. * */ - Crc16(Polynomial aPolynomial); + explicit Crc16(Polynomial aPolynomial); /** * This method initializes the CRC16 computation. diff --git a/src/core/common/locator.hpp b/src/core/common/locator.hpp index f10149f1b..61555cb99 100644 --- a/src/core/common/locator.hpp +++ b/src/core/common/locator.hpp @@ -114,7 +114,7 @@ protected: * @param[in] aInstance A pointer to the otInstance. * */ - InstanceLocator(Instance &aInstance) + explicit InstanceLocator(Instance &aInstance) #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES : mInstance(aInstance) #endif @@ -162,7 +162,7 @@ protected: * @param[in] aOwner A pointer to the owner object (as `void *`). * */ - OwnerLocator(void *aOwner) + explicit OwnerLocator(void *aOwner) #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES : mOwner(aOwner) #endif diff --git a/src/core/common/message.hpp b/src/core/common/message.hpp index a4712fc3e..5c640a59b 100644 --- a/src/core/common/message.hpp +++ b/src/core/common/message.hpp @@ -1244,7 +1244,7 @@ public: } private: - Iterator(Message *aMessage) + explicit Iterator(Message *aMessage) : mMessage(aMessage) { } diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index 561896ced..ff767844e 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -402,7 +402,7 @@ public: * @param[in] aInstance A reference to the OpenThread instance. * */ - ChildInfoIterator(Instance &aInstance); + explicit ChildInfoIterator(Instance &aInstance); /** * This method resets the iterator to start from the first Child Info entry in the list. diff --git a/src/core/common/string.hpp b/src/core/common/string.hpp index 895b0fd9b..99c587fa1 100644 --- a/src/core/common/string.hpp +++ b/src/core/common/string.hpp @@ -109,7 +109,7 @@ public: * @param[in] ... Arguments for the format specification. * */ - String(const char *aFormat, ...) + explicit String(const char *aFormat, ...) : mLength(0) { va_list args; diff --git a/src/core/common/timer.hpp b/src/core/common/timer.hpp index 483a79145..3feb5d531 100644 --- a/src/core/common/timer.hpp +++ b/src/core/common/timer.hpp @@ -295,7 +295,7 @@ protected: * @param[in] aInstance A reference to the instance object. * */ - TimerScheduler(Instance &aInstance) + explicit TimerScheduler(Instance &aInstance) : InstanceLocator(aInstance) , mHead(NULL) { @@ -351,7 +351,7 @@ public: * @param[in] aInstance A reference to the instance object. * */ - TimerMilliScheduler(Instance &aInstance) + explicit TimerMilliScheduler(Instance &aInstance) : TimerScheduler(aInstance) { } diff --git a/src/core/mac/channel_mask.hpp b/src/core/mac/channel_mask.hpp index 423649847..29e79ed08 100644 --- a/src/core/mac/channel_mask.hpp +++ b/src/core/mac/channel_mask.hpp @@ -92,7 +92,7 @@ public: * @param[in] aMask A channel mask (as a `uint32_t` bit-vector mask with bit 0 (lsb) -> channel 0, and so on). * */ - ChannelMask(uint32_t aMask) + explicit ChannelMask(uint32_t aMask) : mMask(aMask) { } diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index c4ea922fe..bc64f5fbb 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -425,7 +425,7 @@ void Mac::SetSupportedChannelMask(const ChannelMask &aMask) { ChannelMask newMask = aMask; - newMask.Intersect(Phy::kSupportedChannels); + newMask.Intersect(ChannelMask(Phy::kSupportedChannels)); VerifyOrExit(newMask != mSupportedChannelMask, GetNotifier().SignalIfFirst(OT_CHANGED_SUPPORTED_CHANNEL_MASK)); mSupportedChannelMask = newMask; diff --git a/src/core/meshcop/dataset.hpp b/src/core/meshcop/dataset.hpp index 9aa50727c..e4a8071c8 100644 --- a/src/core/meshcop/dataset.hpp +++ b/src/core/meshcop/dataset.hpp @@ -63,7 +63,7 @@ public: * @param[in] aType The type of the dataset, active or pending. * */ - Dataset(const Tlv::Type aType); + explicit Dataset(const Tlv::Type aType); /** * This method clears the Dataset. diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index dbbc96c5e..50207c407 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -127,8 +127,8 @@ otError Joiner::Start(const char * aPSKd, memset(mJoinerRouters, 0, sizeof(mJoinerRouters)); - SuccessOrExit(error = - netif.GetMle().Discover(0, netif.GetMac().GetPanId(), true, false, HandleDiscoverResult, this)); + SuccessOrExit(error = netif.GetMle().Discover(Mac::ChannelMask(0), netif.GetMac().GetPanId(), true, false, + HandleDiscoverResult, this)); mVendorName = aVendorName; mVendorModel = aVendorModel; diff --git a/src/core/net/dns_client.hpp b/src/core/net/dns_client.hpp index 14bec05a1..55499297e 100644 --- a/src/core/net/dns_client.hpp +++ b/src/core/net/dns_client.hpp @@ -158,7 +158,7 @@ public: * @param[in] aNetif A reference to the network interface that DNS client should be assigned to. * */ - Client(Ip6::Netif &aNetif) + explicit Client(Ip6::Netif &aNetif) : mSocket(aNetif.GetIp6().GetUdp()) , mMessageId(0) , mRetransmissionTimer(aNetif.GetInstance(), &Client::HandleRetransmissionTimer, this){}; diff --git a/src/core/net/sntp_client.hpp b/src/core/net/sntp_client.hpp index 31e0c5216..48c133c4e 100644 --- a/src/core/net/sntp_client.hpp +++ b/src/core/net/sntp_client.hpp @@ -528,7 +528,7 @@ public: * @param[in] aNetif A reference to the network interface that SNTP client should be assigned to. * */ - Client(Ip6::Netif &aNetif) + explicit Client(Ip6::Netif &aNetif) : mSocket(aNetif.GetIp6().GetUdp()) , mRetransmissionTimer(aNetif.GetInstance(), &Client::HandleRetransmissionTimer, this) , mUnixEra(0){}; diff --git a/src/core/thread/announce_sender.cpp b/src/core/thread/announce_sender.cpp index 5a2afea62..4ac092002 100644 --- a/src/core/thread/announce_sender.cpp +++ b/src/core/thread/announce_sender.cpp @@ -66,7 +66,7 @@ otError AnnounceSenderBase::SendAnnounce(Mac::ChannelMask aMask, uint8_t aCount, VerifyOrExit(aPeriod != 0, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aJitter < aPeriod, error = OT_ERROR_INVALID_ARGS); - aMask.Intersect(Phy::kSupportedChannels); + aMask.Intersect(Mac::ChannelMask(Phy::kSupportedChannels)); VerifyOrExit(!aMask.IsEmpty(), error = OT_ERROR_INVALID_ARGS); mChannelMask = aMask; diff --git a/src/core/thread/network_data.hpp b/src/core/thread/network_data.hpp index 78ea5590b..6ca2bcbc0 100644 --- a/src/core/thread/network_data.hpp +++ b/src/core/thread/network_data.hpp @@ -488,7 +488,7 @@ private: }; public: - NetworkDataIterator(otNetworkDataIterator *aIterator) + explicit NetworkDataIterator(otNetworkDataIterator *aIterator) : mIteratorBuffer(reinterpret_cast(aIterator)) { } diff --git a/src/core/thread/router_table.hpp b/src/core/thread/router_table.hpp index 61ef0c58d..2d626904b 100644 --- a/src/core/thread/router_table.hpp +++ b/src/core/thread/router_table.hpp @@ -56,7 +56,7 @@ public: * @param[in] aInstance A reference to the OpenThread instance. * */ - Iterator(Instance &aInstance); + explicit Iterator(Instance &aInstance); /** * This method resets the iterator to start over. @@ -118,7 +118,7 @@ public: * @param[in] aInstance A reference to the OpenThread instance. * */ - RouterTable(Instance &aInstance); + explicit RouterTable(Instance &aInstance); /** * This method clears the router table. @@ -371,7 +371,7 @@ public: class Iterator { public: - Iterator(Instance &) {} + explicit Iterator(Instance &) {} void Reset(void) {} bool IsDone(void) const { return true; } void Advance(void) {} diff --git a/src/core/utils/channel_monitor.hpp b/src/core/utils/channel_monitor.hpp index 0a631d63c..487837f40 100644 --- a/src/core/utils/channel_monitor.hpp +++ b/src/core/utils/channel_monitor.hpp @@ -102,7 +102,7 @@ public: * @param[in] aInstance A reference to the OpenThread instance. * */ - ChannelMonitor(Instance &aInstance); + explicit ChannelMonitor(Instance &aInstance); /** * This method starts the Channel Monitoring operation. diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index 76f3126ad..2991147a1 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -68,7 +68,7 @@ public: * @param[in] aInstance The OpenThread instance structure. * */ - NcpBase(Instance *aInstance); + explicit NcpBase(Instance *aInstance); /** * This static method returns the pointer to the single NCP instance. diff --git a/src/ncp/ncp_spi.hpp b/src/ncp/ncp_spi.hpp index 4d381a8db..4bcb34784 100644 --- a/src/ncp/ncp_spi.hpp +++ b/src/ncp/ncp_spi.hpp @@ -58,7 +58,7 @@ public: * @param[in] aBuffer Pointer to buffer containing the frame. * */ - SpiFrame(uint8_t *aBuffer) + explicit SpiFrame(uint8_t *aBuffer) : mBuffer(aBuffer) { } @@ -152,7 +152,7 @@ public: * @param[in] aInstance A pointer to the OpenThread instance structure. * */ - NcpSpi(Instance *aInstance); + explicit NcpSpi(Instance *aInstance); private: enum diff --git a/src/ncp/ncp_uart.hpp b/src/ncp/ncp_uart.hpp index a61fa5819..0a4a390df 100644 --- a/src/ncp/ncp_uart.hpp +++ b/src/ncp/ncp_uart.hpp @@ -56,7 +56,7 @@ public: * @param[in] aInstance The OpenThread instance structure. * */ - NcpUart(Instance *aInstance); + explicit NcpUart(Instance *aInstance); /** * This method is called when uart tx is finished. It prepares and sends the next data chunk (if any) to uart. diff --git a/src/ncp/spinel_encoder.hpp b/src/ncp/spinel_encoder.hpp index dad009cbf..0a97e360f 100644 --- a/src/ncp/spinel_encoder.hpp +++ b/src/ncp/spinel_encoder.hpp @@ -59,7 +59,7 @@ public: * @param[in] aNcpBuffer A reference to a `NcpFrameBuffer` where the frames are written. * */ - SpinelEncoder(NcpFrameBuffer &aNcpBuffer) + explicit SpinelEncoder(NcpFrameBuffer &aNcpBuffer) : mNcpBuffer(aNcpBuffer) , mNumOpenStructs(0) , mSavedNumOpenStructs(0)