From 054c185ce94f1a6b9ea3d164f18559f4d45ab84b Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Thu, 6 Apr 2017 19:22:23 -0400 Subject: [PATCH] Build with /WX in Appveyor, fix MSVC compiler warnings --- appveyor.yml | 6 +----- cpp/cmake_modules/SetupCxxFlags.cmake | 4 ++++ cpp/src/arrow/array-test.cc | 14 +++++++------- cpp/src/arrow/builder.h | 4 ++++ cpp/src/arrow/io/file.cc | 6 +++--- cpp/src/arrow/io/io-hdfs-test.cc | 2 +- cpp/src/arrow/ipc/json-internal.cc | 2 +- cpp/src/arrow/ipc/test-common.h | 2 +- cpp/src/arrow/tensor.cc | 2 +- 9 files changed, 23 insertions(+), 19 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 9f3594907d17..b8c26e6e5084 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,12 +30,8 @@ build_script: - cd cpp - mkdir build - cd build - # A lot of features are still deactivated as they do not build on Windows - # * gbenchmark doesn't build with MSVC - - cmake -G "%GENERATOR%" -DARROW_BOOST_USE_SHARED=OFF -DARROW_BUILD_BENCHMARKS=OFF -DARROW_JEMALLOC=OFF -DCMAKE_BUILD_TYPE=Release .. + - cmake -G "%GENERATOR%" -DARROW_CXXFLAGS="/WX" -DARROW_BOOST_USE_SHARED=OFF -DCMAKE_BUILD_TYPE=Release .. - cmake --build . --config Release # test_script: - ctest -VV - - diff --git a/cpp/cmake_modules/SetupCxxFlags.cmake b/cpp/cmake_modules/SetupCxxFlags.cmake index 09a662ec6e58..694e5a37df4b 100644 --- a/cpp/cmake_modules/SetupCxxFlags.cmake +++ b/cpp/cmake_modules/SetupCxxFlags.cmake @@ -26,6 +26,10 @@ CHECK_CXX_COMPILER_FLAG("-maltivec" CXX_SUPPORTS_ALTIVEC) # compiler flags that are common across debug/release builds if (MSVC) + # TODO(wesm): Change usages of C runtime functions that MSVC says are + # insecure, like std::getenv + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # clang-cl set(CXX_COMMON_FLAGS "-EHsc") diff --git a/cpp/src/arrow/array-test.cc b/cpp/src/arrow/array-test.cc index 68b9864301d2..e50f4fd10b08 100644 --- a/cpp/src/arrow/array-test.cc +++ b/cpp/src/arrow/array-test.cc @@ -124,10 +124,10 @@ TEST_F(TestArray, SliceRecomputeNullCount) { TEST_F(TestArray, TestIsNull) { // clang-format off vector null_bitmap = {1, 0, 1, 1, 0, 1, 0, 0, - 1, 0, 1, 1, 0, 1, 0, 0, - 1, 0, 1, 1, 0, 1, 0, 0, - 1, 0, 1, 1, 0, 1, 0, 0, - 1, 0, 0, 1}; + 1, 0, 1, 1, 0, 1, 0, 0, + 1, 0, 1, 1, 0, 1, 0, 0, + 1, 0, 1, 1, 0, 1, 0, 0, + 1, 0, 0, 1}; // clang-format on int64_t null_count = 0; for (uint8_t x : null_bitmap) { @@ -144,7 +144,7 @@ TEST_F(TestArray, TestIsNull) { ASSERT_TRUE(arr->null_bitmap()->Equals(*null_buf.get())); for (size_t i = 0; i < null_bitmap.size(); ++i) { - EXPECT_EQ(null_bitmap[i], !arr->IsNull(i)) << i; + EXPECT_EQ(null_bitmap[i] != 0, !arr->IsNull(i)) << i; } } @@ -334,7 +334,7 @@ void TestPrimitiveBuilder::Check( for (int64_t i = 0; i < result->length(); ++i) { if (nullable) { ASSERT_EQ(valid_bytes_[i] == 0, result->IsNull(i)) << i; } bool actual = BitUtil::GetBit(result->data()->data(), i); - ASSERT_EQ(static_cast(draws_[i]), actual) << i; + ASSERT_EQ(draws_[i] != 0, actual) << i; } ASSERT_TRUE(result->Equals(*expected)); } @@ -1379,7 +1379,7 @@ void ValidateBasicListArray(const ListArray* result, const vector& valu } for (int i = 0; i < result->length(); ++i) { - ASSERT_EQ(!static_cast(is_valid[i]), result->IsNull(i)); + ASSERT_EQ(is_valid[i] == 0, result->IsNull(i)); } ASSERT_EQ(7, result->values()->length()); diff --git a/cpp/src/arrow/builder.h b/cpp/src/arrow/builder.h index 61207a334db3..60cdc4cb3a5d 100644 --- a/cpp/src/arrow/builder.h +++ b/cpp/src/arrow/builder.h @@ -275,6 +275,10 @@ class ARROW_EXPORT BooleanBuilder : public ArrayBuilder { return Status::OK(); } + Status Append(uint8_t val) { + return Append(val != 0); + } + /// Vector append /// /// If passed, valid_bytes is of equal length to values, and any zero byte diff --git a/cpp/src/arrow/io/file.cc b/cpp/src/arrow/io/file.cc index 720be3d6e739..eb4b9fc43884 100644 --- a/cpp/src/arrow/io/file.cc +++ b/cpp/src/arrow/io/file.cc @@ -250,9 +250,9 @@ static inline Status FileRead( int fd, uint8_t* buffer, int64_t nbytes, int64_t* bytes_read) { #if defined(_MSC_VER) if (nbytes > INT32_MAX) { return Status::IOError("Unable to read > 2GB blocks yet"); } - *bytes_read = _read(fd, buffer, static_cast(nbytes)); + *bytes_read = static_cast(_read(fd, buffer, static_cast(nbytes))); #else - *bytes_read = read(fd, buffer, static_cast(nbytes)); + *bytes_read = static_cast(read(fd, buffer, static_cast(nbytes))); #endif if (*bytes_read == -1) { @@ -269,7 +269,7 @@ static inline Status FileWrite(int fd, const uint8_t* buffer, int64_t nbytes) { if (nbytes > INT32_MAX) { return Status::IOError("Unable to write > 2GB blocks to file yet"); } - ret = static_cast(_write(fd, buffer, static_cast(nbytes))); + ret = static_cast(_write(fd, buffer, static_cast(nbytes))); #else ret = static_cast(write(fd, buffer, static_cast(nbytes))); #endif diff --git a/cpp/src/arrow/io/io-hdfs-test.cc b/cpp/src/arrow/io/io-hdfs-test.cc index f3140be0b2da..a2c9c5210b10 100644 --- a/cpp/src/arrow/io/io-hdfs-test.cc +++ b/cpp/src/arrow/io/io-hdfs-test.cc @@ -107,7 +107,7 @@ class TestHdfsClient : public ::testing::Test { const char* port = std::getenv("ARROW_HDFS_TEST_PORT"); const char* user = std::getenv("ARROW_HDFS_TEST_USER"); - ASSERT_TRUE(user) << "Set ARROW_HDFS_TEST_USER"; + ASSERT_TRUE(user != nullptr) << "Set ARROW_HDFS_TEST_USER"; conf_.host = host == nullptr ? "localhost" : host; conf_.user = user; diff --git a/cpp/src/arrow/ipc/json-internal.cc b/cpp/src/arrow/ipc/json-internal.cc index 124c21b8fc02..fe0a7c94226f 100644 --- a/cpp/src/arrow/ipc/json-internal.cc +++ b/cpp/src/arrow/ipc/json-internal.cc @@ -1102,7 +1102,7 @@ class JsonArrayReader { std::vector is_valid; for (const rj::Value& val : json_validity) { DCHECK(val.IsInt()); - is_valid.push_back(static_cast(val.GetInt())); + is_valid.push_back(val.GetInt() != 0); } #define TYPE_CASE(TYPE) \ diff --git a/cpp/src/arrow/ipc/test-common.h b/cpp/src/arrow/ipc/test-common.h index d113531822c9..9e0480d4c363 100644 --- a/cpp/src/arrow/ipc/test-common.h +++ b/cpp/src/arrow/ipc/test-common.h @@ -125,7 +125,7 @@ Status MakeRandomListArray(const std::shared_ptr& child_array, int num_li std::partial_sum(list_sizes.begin(), list_sizes.end(), ++offsets.begin()); // Force invariants - const int64_t child_length = child_array->length(); + const int32_t child_length = static_cast(child_array->length()); offsets[0] = 0; std::replace_if(offsets.begin(), offsets.end(), [child_length](int32_t offset) { return offset > child_length; }, child_length); diff --git a/cpp/src/arrow/tensor.cc b/cpp/src/arrow/tensor.cc index 8bbb97b596e1..d1c4083289f9 100644 --- a/cpp/src/arrow/tensor.cc +++ b/cpp/src/arrow/tensor.cc @@ -86,7 +86,7 @@ const std::string& Tensor::dim_name(int i) const { } int64_t Tensor::size() const { - return std::accumulate(shape_.begin(), shape_.end(), 1, std::multiplies()); + return std::accumulate(shape_.begin(), shape_.end(), 1LL, std::multiplies()); } bool Tensor::is_contiguous() const {