From 0e1c9a79a3a5df8c31e675d66757cc5444fdf5b6 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 15 Jan 2025 11:05:15 -0800 Subject: [PATCH] [style] use `constexpr` instead of anonymous `enum` for constants (#11161) This commit updates a few remaining places where anonymous enums were used to declare constants, replacing them with `static constexpr`. --- src/cli/cli_br.hpp | 11 ++++------- src/core/net/tcp6.hpp | 13 +++++-------- src/core/thread/mle.cpp | 5 +---- src/core/utils/parse_cmdline.cpp | 9 +++------ src/ncp/ncp_base.hpp | 5 +---- tests/unit/test_message.cpp | 9 +++------ tests/unit/test_pool.cpp | 5 +---- 7 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/cli/cli_br.hpp b/src/cli/cli_br.hpp index bc811e7fa..26d56d8b0 100644 --- a/src/cli/cli_br.hpp +++ b/src/cli/cli_br.hpp @@ -77,14 +77,11 @@ public: otError Process(Arg aArgs[]); private: - using Command = CommandEntry
; - + using Command = CommandEntry
; using PrefixType = uint8_t; - enum : PrefixType - { - kPrefixTypeLocal = 1u << 0, - kPrefixTypeFavored = 1u << 1, - }; + + static constexpr PrefixType kPrefixTypeLocal = 1u << 0; + static constexpr PrefixType kPrefixTypeFavored = 1u << 1; enum RouterOutputMode : uint8_t { diff --git a/src/core/net/tcp6.hpp b/src/core/net/tcp6.hpp index 6c65ff4d2..39733b9c4 100644 --- a/src/core/net/tcp6.hpp +++ b/src/core/net/tcp6.hpp @@ -360,14 +360,11 @@ public: friend void ::tcplp_sys_set_timer(struct tcpcb *aTcb, uint8_t aTimerFlag, uint32_t aDelay); friend void ::tcplp_sys_stop_timer(struct tcpcb *aTcb, uint8_t aTimerFlag); - enum : uint8_t - { - kTimerDelack = 0, - kTimerRexmtPersist = 1, - kTimerKeep = 2, - kTimer2Msl = 3, - kNumTimers = 4, - }; + static constexpr uint8_t kTimerDelack = 0; + static constexpr uint8_t kTimerRexmtPersist = 1; + static constexpr uint8_t kTimerKeep = 2; + static constexpr uint8_t kTimer2Msl = 3; + static constexpr uint8_t kNumTimers = 4; static uint8_t TimerFlagToIndex(uint8_t aTimerFlag); diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index ee2c46a2e..20eeae539 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -4094,10 +4094,7 @@ void Mle::Log(MessageAction aAction, MessageType aType, const Ip6::Address &aAdd void Mle::Log(MessageAction aAction, MessageType aType, const Ip6::Address &aAddress, uint16_t aRloc) { - enum : uint8_t - { - kRlocStringSize = 17, - }; + static constexpr uint16_t kRlocStringSize = 17; String rlocString; diff --git a/src/core/utils/parse_cmdline.cpp b/src/core/utils/parse_cmdline.cpp index c05a0d621..32c4a82c2 100644 --- a/src/core/utils/parse_cmdline.cpp +++ b/src/core/utils/parse_cmdline.cpp @@ -108,17 +108,14 @@ Error ParseAsUint32(const char *aString, uint32_t &aUint32) { return ParseUint EntryPool;