diff --git a/script/make-pretty b/script/make-pretty index c9b62dec4..a2508606c 100755 --- a/script/make-pretty +++ b/script/make-pretty @@ -116,6 +116,7 @@ readonly OT_CLANG_TIDY_BUILD_OPTS=( readonly OT_CLANG_TIDY_CHECKS="\ -*,\ +google-explicit-constructor,\ google-readability-casting,\ misc-unused-using-decls,\ modernize-use-bool-literals,\ diff --git a/src/core/backbone_router/multicast_listeners_table.hpp b/src/core/backbone_router/multicast_listeners_table.hpp index 53d9f5f44..132841a1c 100644 --- a/src/core/backbone_router/multicast_listeners_table.hpp +++ b/src/core/backbone_router/multicast_listeners_table.hpp @@ -203,7 +203,7 @@ private: class IteratorBuilder : InstanceLocator { public: - IteratorBuilder(Instance &aInstance) + explicit IteratorBuilder(Instance &aInstance) : InstanceLocator(aInstance) { } diff --git a/src/core/common/message.hpp b/src/core/common/message.hpp index 0fabcc16d..10b602a68 100644 --- a/src/core/common/message.hpp +++ b/src/core/common/message.hpp @@ -392,7 +392,7 @@ public: * security enabled with `kPriorityNormal` priority) would be used. * */ - Settings(const otMessageSettings *aSettings); + explicit Settings(const otMessageSettings *aSettings); /** * This method gets the message priority. diff --git a/src/core/common/pool.hpp b/src/core/common/pool.hpp index e2c4007a9..322df885c 100644 --- a/src/core/common/pool.hpp +++ b/src/core/common/pool.hpp @@ -86,7 +86,7 @@ public: * @param[in] aInstance A reference to the OpenThread instance. * */ - Pool(Instance &aInstance) + explicit Pool(Instance &aInstance) : mFreeList() { for (Type &entry : mPool) diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index d08d5a55a..746679aa2 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -1004,7 +1004,7 @@ private: class ChildInfoIteratorBuilder : public InstanceLocator { public: - ChildInfoIteratorBuilder(Instance &aInstance) + explicit ChildInfoIteratorBuilder(Instance &aInstance) : InstanceLocator(aInstance) { } diff --git a/src/core/common/time_ticker.hpp b/src/core/common/time_ticker.hpp index 43d398a4d..4d733d584 100644 --- a/src/core/common/time_ticker.hpp +++ b/src/core/common/time_ticker.hpp @@ -79,7 +79,7 @@ public: * This constructor initializes the `TimeTicker` instance. * */ - TimeTicker(Instance &aInstance); + explicit TimeTicker(Instance &aInstance); /** * This method registers a receiver with `TimeTicker` to receive periodic ticks. diff --git a/src/core/common/timer.hpp b/src/core/common/timer.hpp index 563ee5379..16bfabc11 100644 --- a/src/core/common/timer.hpp +++ b/src/core/common/timer.hpp @@ -437,7 +437,7 @@ public: * @param[in] aInstance A reference to the instance object. * */ - TimerMicroScheduler(Instance &aInstance) + explicit TimerMicroScheduler(Instance &aInstance) : TimerScheduler(aInstance) { } diff --git a/src/core/net/netif.cpp b/src/core/net/netif.cpp index 4323e87bf..1043c7398 100644 --- a/src/core/net/netif.cpp +++ b/src/core/net/netif.cpp @@ -53,7 +53,7 @@ public: mIsAnycast = aInstance.Get().IsAnycastLocator(aAddress.GetAddress()); } - AddressInfo(const NetifMulticastAddress &aAddress) + explicit AddressInfo(const NetifMulticastAddress &aAddress) { mAddress = &aAddress.GetAddress(); mPrefixLength = kMulticastPrefixLength; diff --git a/src/core/net/netif.hpp b/src/core/net/netif.hpp index e73fdfcb9..ad2ef31fb 100644 --- a/src/core/net/netif.hpp +++ b/src/core/net/netif.hpp @@ -403,7 +403,7 @@ public: * @param[in] aInstance A reference to the OpenThread instance. * */ - Netif(Instance &aInstance); + explicit Netif(Instance &aInstance); /** * This method registers a callback to notify internal IPv6 address changes. diff --git a/src/core/radio/radio.hpp b/src/core/radio/radio.hpp index 74eb68be9..7b7b234ea 100644 --- a/src/core/radio/radio.hpp +++ b/src/core/radio/radio.hpp @@ -195,7 +195,7 @@ public: * @param[in] aInstance A reference to the OpenThread instance. * */ - Radio(Instance &aInstance) + explicit Radio(Instance &aInstance) : InstanceLocator(aInstance) , mCallbacks(aInstance) { diff --git a/src/core/thread/child_table.hpp b/src/core/thread/child_table.hpp index d952c39db..493b8518a 100644 --- a/src/core/thread/child_table.hpp +++ b/src/core/thread/child_table.hpp @@ -161,7 +161,7 @@ public: bool operator!=(const Iterator &aOther) const { return mChild != aOther.mChild; } private: - Iterator(Instance &aInstance) + explicit Iterator(Instance &aInstance) : InstanceLocator(aInstance) , mFilter(Child::StateFilter::kInStateValid) , mChild(nullptr) diff --git a/src/core/thread/link_metrics.cpp b/src/core/thread/link_metrics.cpp index 3c84ed862..7efc700a9 100644 --- a/src/core/thread/link_metrics.cpp +++ b/src/core/thread/link_metrics.cpp @@ -313,7 +313,7 @@ otError LinkMetrics::AppendSingleProbeLinkMetricsReport(Message & aMe if (aLinkMetrics.mPduCount) { metric.Init(); - metric.SetMetricsTypeId(kTypeIdFlagPdu); + metric.SetMetricsTypeId(LinkMetricsTypeIdFlags(kTypeIdFlagPdu)); metric.SetMetricsValue32(aRequestMessage.GetPsduCount()); SuccessOrExit(error = aMessage.AppendBytes(&metric, metric.GetSize())); aLength += metric.GetSize(); @@ -322,7 +322,7 @@ otError LinkMetrics::AppendSingleProbeLinkMetricsReport(Message & aMe if (aLinkMetrics.mLqi) { metric.Init(); - metric.SetMetricsTypeId(kTypeIdFlagLqi); + metric.SetMetricsTypeId(LinkMetricsTypeIdFlags(kTypeIdFlagLqi)); metric.SetMetricsValue8(aRequestMessage.GetAverageLqi()); // IEEE 802.15.4 LQI is in scale 0-255 SuccessOrExit(error = aMessage.AppendBytes(&metric, metric.GetSize())); aLength += metric.GetSize(); @@ -331,7 +331,7 @@ otError LinkMetrics::AppendSingleProbeLinkMetricsReport(Message & aMe if (aLinkMetrics.mLinkMargin) { metric.Init(); - metric.SetMetricsTypeId(kTypeIdFlagLinkMargin); + metric.SetMetricsTypeId(LinkMetricsTypeIdFlags(kTypeIdFlagLinkMargin)); metric.SetMetricsValue8( LinkQualityInfo::ConvertRssToLinkMargin(Get().GetNoiseFloor(), aRequestMessage.GetAverageRss()) * 255 / 130); // Linear scale Link Margin from [0, 130] to [0, 255] @@ -342,7 +342,7 @@ otError LinkMetrics::AppendSingleProbeLinkMetricsReport(Message & aMe if (aLinkMetrics.mRssi) { metric.Init(); - metric.SetMetricsTypeId(kTypeIdFlagRssi); + metric.SetMetricsTypeId(LinkMetricsTypeIdFlags(kTypeIdFlagRssi)); metric.SetMetricsValue8((aRequestMessage.GetAverageRss() + 130) * 255 / 130); // Linear scale rss from [-130, 0] to [0, 255] SuccessOrExit(error = aMessage.AppendBytes(&metric, metric.GetSize())); diff --git a/src/core/thread/link_metrics_tlvs.hpp b/src/core/thread/link_metrics_tlvs.hpp index bad7ee966..5e06158c2 100644 --- a/src/core/thread/link_metrics_tlvs.hpp +++ b/src/core/thread/link_metrics_tlvs.hpp @@ -88,8 +88,8 @@ public: * Constructor for implicit cast from `uint8_t` to `LinkMetricsTypeIdFlags`. * */ - LinkMetricsTypeIdFlags(uint8_t typeIdFlags) - : mTypeIdFlags(typeIdFlags) + explicit LinkMetricsTypeIdFlags(uint8_t aTypeIdFlags) + : mTypeIdFlags(aTypeIdFlags) { } diff --git a/src/core/thread/network_data_notifier.hpp b/src/core/thread/network_data_notifier.hpp index 2c349b755..dcc319562 100644 --- a/src/core/thread/network_data_notifier.hpp +++ b/src/core/thread/network_data_notifier.hpp @@ -61,7 +61,7 @@ public: * @param[in] aInstance The OpenThread instance. * */ - Notifier(Instance &aInstance); + explicit Notifier(Instance &aInstance); /** * Call this method to inform the notifier that new server data is available. diff --git a/src/core/thread/router_table.hpp b/src/core/thread/router_table.hpp index f21fef24c..c798a4f9a 100644 --- a/src/core/thread/router_table.hpp +++ b/src/core/thread/router_table.hpp @@ -417,7 +417,7 @@ private: class IteratorBuilder : public InstanceLocator { public: - IteratorBuilder(Instance &aInstance) + explicit IteratorBuilder(Instance &aInstance) : InstanceLocator(aInstance) { } diff --git a/src/core/thread/topology.hpp b/src/core/thread/topology.hpp index 2d1240439..a3c28b51a 100644 --- a/src/core/thread/topology.hpp +++ b/src/core/thread/topology.hpp @@ -690,7 +690,7 @@ public: * @param[in] aFilter An IPv6 address type filter restricting iterator to certain type of addresses. * */ - AddressIterator(const Child &aChild, Ip6::Address::TypeFilter aFilter = Ip6::Address::kTypeAny) + explicit AddressIterator(const Child &aChild, Ip6::Address::TypeFilter aFilter = Ip6::Address::kTypeAny) : AddressIterator(aChild, 0, aFilter) { } diff --git a/src/core/utils/flash.hpp b/src/core/utils/flash.hpp index 1f1fb40bd..ecac26c35 100644 --- a/src/core/utils/flash.hpp +++ b/src/core/utils/flash.hpp @@ -53,7 +53,7 @@ public: * Constructor. * */ - Flash(Instance &aInstance) + explicit Flash(Instance &aInstance) : InstanceLocator(aInstance) { } diff --git a/src/core/utils/lookup_table.hpp b/src/core/utils/lookup_table.hpp index bedf13a3e..92e4e3950 100644 --- a/src/core/utils/lookup_table.hpp +++ b/src/core/utils/lookup_table.hpp @@ -59,7 +59,7 @@ public: * @param[in] aName The null-terminated name string with which to initialize the entry. * */ - constexpr Entry(const char *aName) + constexpr explicit Entry(const char *aName) : mName(aName) { } diff --git a/tests/unit/test_lookup_table.cpp b/tests/unit/test_lookup_table.cpp index 17fb658b3..7e06d9776 100644 --- a/tests/unit/test_lookup_table.cpp +++ b/tests/unit/test_lookup_table.cpp @@ -41,7 +41,7 @@ typedef ot::Utils::LookupTable::Entry Entry; struct TableEntryBase { - constexpr TableEntryBase(uint8_t aValue) + constexpr explicit TableEntryBase(uint8_t aValue) : mValue(aValue) { } @@ -76,8 +76,8 @@ void TestLookupTable(void) {"sekiro", 10}, {"tomb raider", 9}, {"uncharted", 9}, }; - constexpr Entry kUnsortedTable[] = {{"z"}, {"a"}, {"b"}}; - constexpr Entry kDuplicateEntryTable[] = {"duplicate", "duplicate"}; + constexpr Entry kUnsortedTable[] = {Entry("z"), Entry("a"), Entry("b")}; + constexpr Entry kDuplicateEntryTable[] = {Entry("duplicate"), Entry("duplicate")}; static_assert(ot::Utils::LookupTable::IsSorted(kTable), "LookupTable::IsSorted() failed"); static_assert(!ot::Utils::LookupTable::IsSorted(kUnsortedTable), diff --git a/tests/unit/test_lowpan.hpp b/tests/unit/test_lowpan.hpp index 16b5e5a13..e069c9c35 100644 --- a/tests/unit/test_lowpan.hpp +++ b/tests/unit/test_lowpan.hpp @@ -59,7 +59,7 @@ public: * Default constructor for the object. * */ - TestIphcVector(const char *aTestName) + explicit TestIphcVector(const char *aTestName) { memset(reinterpret_cast(this), 0, sizeof(TestIphcVector)); mTestName = aTestName; diff --git a/tests/unit/test_netif.cpp b/tests/unit/test_netif.cpp index f8ddc2aa5..ca1ace0f8 100644 --- a/tests/unit/test_netif.cpp +++ b/tests/unit/test_netif.cpp @@ -44,7 +44,7 @@ namespace ot { class TestNetif : public Ip6::Netif { public: - TestNetif(Instance &aInstance) + explicit TestNetif(Instance &aInstance) : Ip6::Netif(aInstance) { } diff --git a/tests/unit/test_timer.cpp b/tests/unit/test_timer.cpp index ed73378fa..9ff02ab2e 100644 --- a/tests/unit/test_timer.cpp +++ b/tests/unit/test_timer.cpp @@ -86,7 +86,7 @@ void InitCounters(void) template class TestTimer : public TimerType { public: - TestTimer(ot::Instance &aInstance) + explicit TestTimer(ot::Instance &aInstance) : TimerType(aInstance, TestTimer::HandleTimerFired, nullptr) , mFiredCounter(0) {