Skip to content

Commit

Permalink
Fix MSVC warnings in crc32c_unittest.cc. (google#3)
Browse files Browse the repository at this point in the history
This also modifies the CMake configuration, so relevant build targets
will be compiled with /WX (warnings-as-errors) on MSVC. This should help
us catch similar errors in CI in the future.
  • Loading branch information
pwnall authored and cmumford committed Aug 31, 2017
1 parent 52fbb76 commit db73a3f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ target_include_directories(crc32c
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# Warnings as errors in Visual Studio for this project's targets.
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_property(TARGET crc32c APPEND PROPERTY COMPILE_OPTIONS "/WX")
set_property(TARGET crc32c_arm64 APPEND PROPERTY COMPILE_OPTIONS "/WX")
set_property(TARGET crc32c_sse42 APPEND PROPERTY COMPILE_OPTIONS "/WX")
endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")

if(CRC32C_BUILD_TESTS)
enable_testing()

Expand All @@ -286,6 +293,12 @@ if(CRC32C_BUILD_TESTS)
"${PROJECT_SOURCE_DIR}/src/crc32c_test_main.cc"
)
target_link_libraries(crc32c_tests crc32c gtest)

# Warnings as errors in Visual Studio for this project's targets.
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_property(TARGET crc32c_tests APPEND PROPERTY COMPILE_OPTIONS "/WX")
endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")

if(CRC32C_USE_GLOG)
target_link_libraries(crc32c_tests glog)
endif(CRC32C_USE_GLOG)
Expand All @@ -311,6 +324,11 @@ if(CRC32C_BUILD_BENCHMARKS)
if(CRC32C_USE_GLOG)
target_link_libraries(crc32c_bench glog)
endif(CRC32C_USE_GLOG)

# Warnings as errors in Visual Studio for this project's targets.
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_property(TARGET crc32c_bench APPEND PROPERTY COMPILE_OPTIONS "/WX")
endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
endif(CRC32C_BUILD_BENCHMARKS)

if(CRC32C_INSTALL)
Expand Down
2 changes: 1 addition & 1 deletion src/crc32c_sse42.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ uint32_t ExtendSse42(uint32_t crc, const uint8_t* data, size_t size) {
STEP8(l64, p);
}

l = l64;
l = static_cast<uint32_t>(l64);
// Process the last few bytes.
while (p != e) {
STEP1;
Expand Down
2 changes: 1 addition & 1 deletion src/crc32c_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TEST(CRC32CTest, Crc32cStdString) {
EXPECT_EQ(static_cast<uint32_t>(0x8a9136aa), crc32c::Crc32c(buf));

for (size_t i = 0; i < 32; ++i)
buf[i] = static_cast<char>(0xff);
buf[i] = '\xff';
EXPECT_EQ(static_cast<uint32_t>(0x62a8ab43), crc32c::Crc32c(buf));

for (size_t i = 0; i < 32; ++i)
Expand Down

0 comments on commit db73a3f

Please sign in to comment.