Skip to content

Commit 203fdb0

Browse files
paleolimbotassignUser
authored andcommitted
GH-39185: [C++] Remove compiler warnings with -Wconversion -Wno-sign-conversion in public headers (#39186)
### Rationale for this change The R package has a warning from CRAN to fix a failure to compile with `-Wconversion -Wno-sign-conversion -Werror`. Some of these errors we control and can patch easily; however, the ones in the Arrow C++ portion are more difficult to work around (hence the separate PR). See #39138 for all reported errors (including those in just the R package). ### What changes are included in this PR? The requisite `static_cast<>()`s were added to silence the warnings. ### Are these changes tested? By existing tests. We may add a future R nightly job that runs with these warning flags. ### Are there any user-facing changes? No * Closes: #39185 Authored-by: Dewey Dunnington <[email protected]> Signed-off-by: Dewey Dunnington <[email protected]>
1 parent 740889f commit 203fdb0

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

cpp/src/arrow/util/bit_util.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ void ClearBitmap(uint8_t* data, int64_t offset, int64_t length);
335335
/// ref: https://stackoverflow.com/a/59523400
336336
template <typename Word>
337337
constexpr Word PrecedingWordBitmask(unsigned int const i) {
338-
return (static_cast<Word>(i < sizeof(Word) * 8) << (i & (sizeof(Word) * 8 - 1))) - 1;
338+
return static_cast<Word>(static_cast<Word>(i < sizeof(Word) * 8)
339+
<< (i & (sizeof(Word) * 8 - 1))) -
340+
1;
339341
}
340342
static_assert(PrecedingWordBitmask<uint8_t>(0) == 0x00, "");
341343
static_assert(PrecedingWordBitmask<uint8_t>(4) == 0x0f, "");
@@ -357,8 +359,9 @@ constexpr Word SpliceWord(int n, Word low, Word high) {
357359
template <int batch_size>
358360
void PackBits(const uint32_t* values, uint8_t* out) {
359361
for (int i = 0; i < batch_size / 8; ++i) {
360-
*out++ = (values[0] | values[1] << 1 | values[2] << 2 | values[3] << 3 |
361-
values[4] << 4 | values[5] << 5 | values[6] << 6 | values[7] << 7);
362+
*out++ = static_cast<uint8_t>(values[0] | values[1] << 1 | values[2] << 2 |
363+
values[3] << 3 | values[4] << 4 | values[5] << 5 |
364+
values[6] << 6 | values[7] << 7);
362365
values += 8;
363366
}
364367
}

cpp/src/arrow/util/bitmap_generate.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ void GenerateBitsUnrolled(uint8_t* bitmap, int64_t start_offset, int64_t length,
9090
for (int i = 0; i < 8; ++i) {
9191
out_results[i] = g();
9292
}
93-
*cur++ = (out_results[0] | out_results[1] << 1 | out_results[2] << 2 |
94-
out_results[3] << 3 | out_results[4] << 4 | out_results[5] << 5 |
95-
out_results[6] << 6 | out_results[7] << 7);
93+
*cur++ = static_cast<uint8_t>(out_results[0] | out_results[1] << 1 |
94+
out_results[2] << 2 | out_results[3] << 3 |
95+
out_results[4] << 4 | out_results[5] << 5 |
96+
out_results[6] << 6 | out_results[7] << 7);
9697
}
9798

9899
int64_t remaining_bits = remaining % 8;

0 commit comments

Comments
 (0)