You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by as...@apache.org on 2023/12/23 00:02:18 UTC

(arrow) 01/05: GH-39185: [C++] Remove compiler warnings with `-Wconversion -Wno-sign-conversion` in public headers (#39186)

This is an automated email from the ASF dual-hosted git repository.

assignuser pushed a commit to branch maint-14.0.2-cran
in repository https://gitbox.apache.org/repos/asf/arrow.git

commit 203fdb0af2f8d7cae46579242d9740b19604f2a3
Author: Dewey Dunnington <de...@fishandwhistle.net>
AuthorDate: Tue Dec 12 17:07:56 2023 -0400

    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 <de...@fishandwhistle.net>
    Signed-off-by: Dewey Dunnington <de...@fishandwhistle.net>
---
 cpp/src/arrow/util/bit_util.h        | 9 ++++++---
 cpp/src/arrow/util/bitmap_generate.h | 7 ++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/cpp/src/arrow/util/bit_util.h b/cpp/src/arrow/util/bit_util.h
index 04ab07af1d..1d3a1dc245 100644
--- a/cpp/src/arrow/util/bit_util.h
+++ b/cpp/src/arrow/util/bit_util.h
@@ -335,7 +335,9 @@ void ClearBitmap(uint8_t* data, int64_t offset, int64_t length);
 /// ref: https://stackoverflow.com/a/59523400
 template <typename Word>
 constexpr Word PrecedingWordBitmask(unsigned int const i) {
-  return (static_cast<Word>(i < sizeof(Word) * 8) << (i & (sizeof(Word) * 8 - 1))) - 1;
+  return static_cast<Word>(static_cast<Word>(i < sizeof(Word) * 8)
+                           << (i & (sizeof(Word) * 8 - 1))) -
+         1;
 }
 static_assert(PrecedingWordBitmask<uint8_t>(0) == 0x00, "");
 static_assert(PrecedingWordBitmask<uint8_t>(4) == 0x0f, "");
@@ -357,8 +359,9 @@ constexpr Word SpliceWord(int n, Word low, Word high) {
 template <int batch_size>
 void PackBits(const uint32_t* values, uint8_t* out) {
   for (int i = 0; i < batch_size / 8; ++i) {
-    *out++ = (values[0] | values[1] << 1 | values[2] << 2 | values[3] << 3 |
-              values[4] << 4 | values[5] << 5 | values[6] << 6 | values[7] << 7);
+    *out++ = static_cast<uint8_t>(values[0] | values[1] << 1 | values[2] << 2 |
+                                  values[3] << 3 | values[4] << 4 | values[5] << 5 |
+                                  values[6] << 6 | values[7] << 7);
     values += 8;
   }
 }
diff --git a/cpp/src/arrow/util/bitmap_generate.h b/cpp/src/arrow/util/bitmap_generate.h
index 5efc5d5a1d..52a1e228e0 100644
--- a/cpp/src/arrow/util/bitmap_generate.h
+++ b/cpp/src/arrow/util/bitmap_generate.h
@@ -90,9 +90,10 @@ void GenerateBitsUnrolled(uint8_t* bitmap, int64_t start_offset, int64_t length,
     for (int i = 0; i < 8; ++i) {
       out_results[i] = g();
     }
-    *cur++ = (out_results[0] | out_results[1] << 1 | out_results[2] << 2 |
-              out_results[3] << 3 | out_results[4] << 4 | out_results[5] << 5 |
-              out_results[6] << 6 | out_results[7] << 7);
+    *cur++ = static_cast<uint8_t>(out_results[0] | out_results[1] << 1 |
+                                  out_results[2] << 2 | out_results[3] << 3 |
+                                  out_results[4] << 4 | out_results[5] << 5 |
+                                  out_results[6] << 6 | out_results[7] << 7);
   }
 
   int64_t remaining_bits = remaining % 8;