From 83418105e39daa68a3349337000ad34a8d302091 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 11 Mar 2017 08:45:11 +0000 Subject: [PATCH] static_cast assignments by default. This can be disabled by defining VWR_WITH_UNCASTED_ASSIGNMENT. --- include/vectorwrapper/vectorwrapper.inl | 4 ++++ test/CMakeLists.txt | 14 +++++++++++--- test/unit/test_conversions.cpp | 9 +++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/vectorwrapper/vectorwrapper.inl b/include/vectorwrapper/vectorwrapper.inl index 5a29b9e..496e48b 100644 --- a/include/vectorwrapper/vectorwrapper.inl +++ b/include/vectorwrapper/vectorwrapper.inl @@ -176,7 +176,11 @@ namespace vwr { template inline Vec& assign (Vec& parLeft, const Vec& parRight) { for (size_type z = 0; z < D; ++z) { +#if defined(VWR_WITH_UNCASTED_ASSIGNMENT) parLeft[z] = parRight[z]; +#else + parLeft[z] = static_cast::scalar_type>(parRight[z]); +#endif } return parLeft; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3c91c52..1d96ca3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR) include(CTest) -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -std=c++11") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -std=c++11") - add_subdirectory(gtest-1.7.0) set(GTEST_MAIN_CPP "${CMAKE_SOURCE_DIR}/gtest-1.7.0/src/gtest_main.cc") set(UNITTEST_DATA_DIR "${CMAKE_SOURCE_DIR}/../data") @@ -12,6 +9,17 @@ set(UNITTEST_DATA_DIR "${CMAKE_SOURCE_DIR}/../data") include_directories(SYSTEM gtest-1.7.0/include ) + +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -std=c++11") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -std=c++11") + +add_definitions( + -Wall + -Wextra + -Wpedantic + -Wconversion +) + include_directories(../include) add_subdirectory(unit) add_subdirectory(unit_noconv) diff --git a/test/unit/test_conversions.cpp b/test/unit/test_conversions.cpp index 5bc9df0..36ac194 100644 --- a/test/unit/test_conversions.cpp +++ b/test/unit/test_conversions.cpp @@ -53,3 +53,12 @@ TEST(vwr, conversion) { test_tvec3(p3.cast(), p3.x(), p3.y(), p3.z()); } } + +TEST(vwr, cast) { + using namespace vwr; + + svec2 s(10.0f); + ivec2 i = static_cast(s); + EXPECT_EQ(i.x(), 10); + EXPECT_EQ(i.y(), 10); +}