From bb8bc31e58e09ddc9f278fb848dfa30faddfd625 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Wed, 22 Apr 2026 12:49:29 +0000 Subject: [PATCH] fix: lint warnings from our clang-tidy enum cast check I missed some cases in https://gerrit.lix.systems/c/lix/+/5490, which is not surprising given that I didn't have a lint for it at the time. Some of these have JSON deserializers, which is kind of scary (in that it was UB). Probably no impact, again, due to the lack of -fstrict-enums, but still, yikes! Change-Id: I895a8bfdd9972d8ade9fa6f5aa30845d6a6a6964 --- lix/libexpr/eval-cache.hh | 2 +- lix/libexpr/value.hh | 3 +++ lix/libutil/logging.hh | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lix/libexpr/eval-cache.hh b/lix/libexpr/eval-cache.hh index bd8541b49..5135b0fac 100644 --- a/lix/libexpr/eval-cache.hh +++ b/lix/libexpr/eval-cache.hh @@ -53,7 +53,7 @@ public: ref getRoot(); }; -enum AttrType { +enum AttrType : uint8_t { Placeholder = 0, FullAttrs = 1, String = 2, diff --git a/lix/libexpr/value.hh b/lix/libexpr/value.hh index bf20f2c5f..0e92e08d5 100644 --- a/lix/libexpr/value.hh +++ b/lix/libexpr/value.hh @@ -284,6 +284,7 @@ private: InternalType internalType() const { + // NOLINTNEXTLINE(lix-cast-to-non-fixed-enum): TAG_MASK ensures it's in range return InternalType(raw & TAG_MASK); } @@ -723,6 +724,8 @@ public: Type type() const { + // TAG_MASK == 7, max enumerator is 5, so all possible values are in range + // NOLINTNEXTLINE(lix-cast-to-non-fixed-enum) return Type(raw & TAG_MASK); } }; diff --git a/lix/libutil/logging.hh b/lix/libutil/logging.hh index 0e4a0ae9b..a1103a29c 100644 --- a/lix/libutil/logging.hh +++ b/lix/libutil/logging.hh @@ -12,7 +12,7 @@ namespace nix { -typedef enum { +enum ActivityType : uint8_t { actUnknown = 0, actCopyPath = 100, actFileTransfer = 101, @@ -47,12 +47,12 @@ typedef enum { */ actPostBuildHook = 110, actBuildWaiting = 111, -} ActivityType; +}; template<> struct json::is_integral_enum : std::true_type {}; -typedef enum { +enum ResultType : uint8_t { /** Fields: * 0: int: bytes linked */ @@ -88,7 +88,7 @@ typedef enum { * 0: string: last line */ resPostBuildLogLine = 107, -} ResultType; +}; template<> struct json::is_integral_enum : std::true_type {};