Skip to content

Commit

Permalink
GroupVarint type casting
Browse files Browse the repository at this point in the history
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<unsigned int>::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:52:3)' and 'folly::detail::GroupVarintBase<unsigned int>::(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<unsigned int>::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:52:3)' and 'folly::detail::GroupVarintBase<unsigned int>::(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<unsigned long long>::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:52:3)' and 'folly::detail::GroupVarintBase<unsigned long long>::(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<unsigned long long>::(unnamed enum at fbcode/folly/detail/GroupVarintDetail.h:52:3)' and 'folly::detail::GroupVarintBase<unsigned long long>::(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
  • Loading branch information
Naris Siamwalla authored and facebook-github-bot committed Sep 30, 2024
1 parent 4ab180a commit db653be
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions folly/GroupVarint.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class GroupVarint<uint32_t> : public detail::GroupVarintBase<uint32_t> {
* 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);
}

/**
Expand Down Expand Up @@ -132,8 +133,8 @@ class GroupVarint<uint32_t> : public detail::GroupVarintBase<uint32_t> {
* 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));
}

/**
Expand Down Expand Up @@ -277,8 +278,8 @@ class GroupVarint<uint64_t> : public detail::GroupVarintBase<uint64_t> {
*/
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);
}

/**
Expand Down Expand Up @@ -340,8 +341,8 @@ class GroupVarint<uint64_t> : public detail::GroupVarintBase<uint64_t> {
*/
static size_t encodedSize(const char* p) {
uint16_t n = loadUnaligned<uint16_t>(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);
}

/**
Expand Down

0 comments on commit db653be

Please sign in to comment.