From db653bec432766ad6c6a0a86d685fa9a200e79fa Mon Sep 17 00:00:00 2001 From: Naris Siamwalla Date: Mon, 30 Sep 2024 10:26:58 -0700 Subject: [PATCH] GroupVarint type casting Summary: Pulled out one of the fixes in D63028314 into this diff. The rest of the D63028314 fixes the this-capture compiler warning-turned-error, but that's being suppressed globally (for just Mac builds) via https://www.internalfb.com/code/fbsource/[147e83ce8584d0a790b68a5e9196e84e4834179d]/fbcode/tools/build/buck/gen_modes.py?lines=3764 Both "xbat" which is Xcode 16 clang, and "pika-16", based off a branch cut that brings pika to a clang close to Xcode 16 clang fail with this error: ``` fbcode/folly/GroupVarint.h:80:24: error: arithmetic between different enumeration types ('folly::detail::GroupVarintBase::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:52:3)' and 'folly::detail::GroupVarintBase::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:60:3)') is deprecated [-Werror,-Wdeprecated-anon-enum-enum-conversion] 80 | return kHeaderSize + kGroupSize + key(a) + key(b) + key(c) + key(d); | ~~~~~~~~~~~ ^ ~~~~~~~~~~ fbcode/folly/GroupVarint.h:135:24: error: arithmetic between different enumeration types ('folly::detail::GroupVarintBase::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:52:3)' and 'folly::detail::GroupVarintBase::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:60:3)') is deprecated [-Werror,-Wdeprecated-anon-enum-enum-conversion] 135 | return kHeaderSize + kGroupSize + b0key(uint8_t(*p)) + b1key(uint8_t(*p)) + | ~~~~~~~~~~~ ^ ~~~~~~~~~~ fbcode/folly/GroupVarint.h:280:24: error: arithmetic between different enumeration types ('folly::detail::GroupVarintBase::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:52:3)' and 'folly::detail::GroupVarintBase::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:60:3)') is deprecated [-Werror,-Wdeprecated-anon-enum-enum-conversion] 280 | return kHeaderSize + kGroupSize + key(a) + key(b) + key(c) + key(d) + | ~~~~~~~~~~~ ^ ~~~~~~~~~~ fbcode/folly/GroupVarint.h:343:24: error: arithmetic between different enumeration types ('folly::detail::GroupVarintBase::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:52:3)' and 'folly::detail::GroupVarintBase::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:60:3)') is deprecated [-Werror,-Wdeprecated-anon-enum-enum-conversion] 343 | return kHeaderSize + kGroupSize + b0key(n) + b1key(n) + b2key(n) + | ~~~~~~~~~~~ ^ ~~~~~~~~~~ 4 errors generated. ``` This diff type-casts the offending args. Reviewed By: Gownta Differential Revision: D63461177 fbshipit-source-id: 89e16365baef5ba8711c0cacb9bd6e44aa25c480 --- folly/GroupVarint.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/folly/GroupVarint.h b/folly/GroupVarint.h index e364431f2c0..741c5de6e8a 100644 --- a/folly/GroupVarint.h +++ b/folly/GroupVarint.h @@ -77,7 +77,8 @@ class GroupVarint : public detail::GroupVarintBase { * Return the number of bytes used to encode these four values. */ static size_t size(uint32_t a, uint32_t b, uint32_t c, uint32_t d) { - return kHeaderSize + kGroupSize + key(a) + key(b) + key(c) + key(d); + return (size_t)kHeaderSize + (size_t)kGroupSize + key(a) + key(b) + key(c) + + key(d); } /** @@ -132,8 +133,8 @@ class GroupVarint : public detail::GroupVarintBase { * return the number of bytes used by the encoding. */ static size_t encodedSize(const char* p) { - return kHeaderSize + kGroupSize + b0key(uint8_t(*p)) + b1key(uint8_t(*p)) + - b2key(uint8_t(*p)) + b3key(uint8_t(*p)); + return (size_t)kHeaderSize + (size_t)kGroupSize + b0key(uint8_t(*p)) + + b1key(uint8_t(*p)) + b2key(uint8_t(*p)) + b3key(uint8_t(*p)); } /** @@ -277,8 +278,8 @@ class GroupVarint : public detail::GroupVarintBase { */ static size_t size( uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) { - return kHeaderSize + kGroupSize + key(a) + key(b) + key(c) + key(d) + - key(e); + return (size_t)kHeaderSize + (size_t)kGroupSize + key(a) + key(b) + key(c) + + key(d) + key(e); } /** @@ -340,8 +341,8 @@ class GroupVarint : public detail::GroupVarintBase { */ static size_t encodedSize(const char* p) { uint16_t n = loadUnaligned(p); - return kHeaderSize + kGroupSize + b0key(n) + b1key(n) + b2key(n) + - b3key(n) + b4key(n); + return (size_t)kHeaderSize + (size_t)kGroupSize + b0key(n) + b1key(n) + + b2key(n) + b3key(n) + b4key(n); } /**