From 1ad55c5016339b83b7eec98c31007e0aee57d2bf Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 7 Jul 2017 11:26:12 +0430 Subject: [PATCH] Reduced warnings when using very strict compilation flags #646 --- CMakeLists.txt | 2 +- glm/detail/func_common.inl | 40 ++++++++++++++++++++++++++++---- glm/detail/func_common_simd.inl | 2 +- glm/detail/func_integer.inl | 12 +++++----- glm/detail/func_integer_simd.inl | 8 +++---- glm/detail/func_matrix_simd.inl | 10 ++++---- glm/detail/type_half.inl | 12 +++++----- readme.md | 3 ++- 8 files changed, 61 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5c87550f..f0f99dc5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ include(CMakePackageConfigHelpers) enable_testing() -add_definitions(-D_CRT_SECURE_NO_WARNINGS) +add_definitions(-D_CRT_SECURE_NO_WARNINGS -g -Weverything -Wpedantic -Werror -Wno-padded -Wno-c++98-compat -Wno-documentation -std=c++11) option(GLM_STATIC_LIBRARY_ENABLE "GLM static library" OFF) if(GLM_STATIC_LIBRARY_ENABLE) diff --git a/glm/detail/func_common.inl b/glm/detail/func_common.inl index a78e3d38a..67fda4833 100644 --- a/glm/detail/func_common.inl +++ b/glm/detail/func_common.inl @@ -696,7 +696,15 @@ namespace detail GLM_FUNC_QUALIFIER int floatBitsToInt(float const & v) { - return reinterpret_cast(const_cast(v)); + union + { + float in; + int out; + } u; + + u.in = v; + + return u.out; } template class vecType, length_t L, precision P> @@ -707,7 +715,15 @@ namespace detail GLM_FUNC_QUALIFIER uint floatBitsToUint(float const & v) { - return reinterpret_cast(const_cast(v)); + union + { + float in; + uint out; + } u; + + u.in = v; + + return u.out; } template class vecType, length_t L, precision P> @@ -718,7 +734,15 @@ namespace detail GLM_FUNC_QUALIFIER float intBitsToFloat(int const & v) { - return reinterpret_cast(const_cast(v)); + union + { + int in; + float out; + } u; + + u.in = v; + + return u.out; } template class vecType, length_t L, precision P> @@ -729,7 +753,15 @@ namespace detail GLM_FUNC_QUALIFIER float uintBitsToFloat(uint const & v) { - return reinterpret_cast(const_cast(v)); + union + { + uint in; + float out; + } u; + + u.in = v; + + return u.out; } template class vecType, length_t L, precision P> diff --git a/glm/detail/func_common_simd.inl b/glm/detail/func_common_simd.inl index e6daa269a..2b6ac5fa3 100644 --- a/glm/detail/func_common_simd.inl +++ b/glm/detail/func_common_simd.inl @@ -191,7 +191,7 @@ namespace detail { GLM_FUNC_QUALIFIER static vec<4, float, P> call(vec<4, float, P> const & x, vec<4, float, P> const & y, vec<4, bool, P> const & a) { - __m128i const Load = _mm_set_epi32(-(int)a.w, -(int)a.z, -(int)a.y, -(int)a.x); + __m128i const Load = _mm_set_epi32(-static_cast(a.w), -static_cast(a.z), -static_cast(a.y), -static_cast(a.x)); __m128 const Mask = _mm_castsi128_ps(Load); vec<4, float, P> Result(uninitialize); diff --git a/glm/detail/func_integer.inl b/glm/detail/func_integer.inl index d4b184c88..8c3b1dd08 100644 --- a/glm/detail/func_integer.inl +++ b/glm/detail/func_integer.inl @@ -298,12 +298,12 @@ namespace detail GLM_FUNC_QUALIFIER vecType bitfieldReverse(vecType const& v) { vecType x(v); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 2>::call(x, T(0x5555555555555555ull), static_cast( 1)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 4>::call(x, T(0x3333333333333333ull), static_cast( 2)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 8>::call(x, T(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 16>::call(x, T(0x00FF00FF00FF00FFull), static_cast( 8)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 32>::call(x, T(0x0000FFFF0000FFFFull), static_cast(16)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 64>::call(x, T(0x00000000FFFFFFFFull), static_cast(32)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 2>::call(x, static_cast(0x5555555555555555ull), static_cast( 1)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 4>::call(x, static_cast(0x3333333333333333ull), static_cast( 2)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 8>::call(x, static_cast(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 16>::call(x, static_cast(0x00FF00FF00FF00FFull), static_cast( 8)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 32>::call(x, static_cast(0x0000FFFF0000FFFFull), static_cast(16)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 64>::call(x, static_cast(0x00000000FFFFFFFFull), static_cast(32)); return x; } diff --git a/glm/detail/func_integer_simd.inl b/glm/detail/func_integer_simd.inl index ddff75bab..095adfb94 100644 --- a/glm/detail/func_integer_simd.inl +++ b/glm/detail/func_integer_simd.inl @@ -11,11 +11,11 @@ namespace detail template struct compute_bitfieldReverseStep<4, uint32, P, vec, true, true> { - GLM_FUNC_QUALIFIER static vec<4, uint32, P> call(vec<4, uint32, P> const & v, uint32 Mask, uint32 Shift) + GLM_FUNC_QUALIFIER static vec<4, uint32, P> call(vec<4, uint32, P> const& v, uint32 Mask, uint32 Shift) { __m128i const set0 = v.data; - __m128i const set1 = _mm_set1_epi32(Mask); + __m128i const set1 = _mm_set1_epi32(static_cast(Mask)); __m128i const and1 = _mm_and_si128(set0, set1); __m128i const sft1 = _mm_slli_epi32(and1, Shift); @@ -32,11 +32,11 @@ namespace detail template struct compute_bitfieldBitCountStep<4, uint32, P, vec, true, true> { - GLM_FUNC_QUALIFIER static vec<4, uint32, P> call(vec<4, uint32, P> const & v, uint32 Mask, uint32 Shift) + GLM_FUNC_QUALIFIER static vec<4, uint32, P> call(vec<4, uint32, P> const& v, uint32 Mask, uint32 Shift) { __m128i const set0 = v.data; - __m128i const set1 = _mm_set1_epi32(Mask); + __m128i const set1 = _mm_set1_epi32(static_cast(Mask)); __m128i const and0 = _mm_and_si128(set0, set1); __m128i const sft0 = _mm_slli_epi32(set0, Shift); __m128i const and1 = _mm_and_si128(sft0, set1); diff --git a/glm/detail/func_matrix_simd.inl b/glm/detail/func_matrix_simd.inl index 99491866a..bf5e5ee80 100644 --- a/glm/detail/func_matrix_simd.inl +++ b/glm/detail/func_matrix_simd.inl @@ -19,9 +19,9 @@ namespace detail { mat<4, 4, float, P> result(uninitialize); glm_mat4_matrixCompMult( - *(glm_vec4 const (*)[4])&x[0].data, - *(glm_vec4 const (*)[4])&y[0].data, - *(glm_vec4(*)[4])&result[0].data); + *static_cast(&x[0].data), + *static_cast(&y[0].data), + *static_cast(&result[0].data)); return result; } }; @@ -33,8 +33,8 @@ namespace detail { mat<4, 4, float, P> result(uninitialize); glm_mat4_transpose( - *(glm_vec4 const (*)[4])&m[0].data, - *(glm_vec4(*)[4])&result[0].data); + *static_cast(&m[0].data), + *static_cast(&result[0].data)); return result; } }; diff --git a/glm/detail/type_half.inl b/glm/detail/type_half.inl index 78d3e2610..fa049f7e5 100644 --- a/glm/detail/type_half.inl +++ b/glm/detail/type_half.inl @@ -46,7 +46,7 @@ namespace detail // detail::uif32 result; - result.i = (unsigned int)(s << 31); + result.i = static_cast(s << 31); return result.f; } else @@ -74,7 +74,7 @@ namespace detail // uif32 result; - result.i = (unsigned int)((s << 31) | 0x7f800000); + result.i = static_cast((s << 31) | 0x7f800000); return result.f; } else @@ -84,7 +84,7 @@ namespace detail // uif32 result; - result.i = (unsigned int)((s << 31) | 0x7f800000 | (m << 13)); + result.i = static_cast((s << 31) | 0x7f800000 | (m << 13)); return result.f; } } @@ -101,15 +101,15 @@ namespace detail // uif32 Result; - Result.i = (unsigned int)((s << 31) | (e << 23) | m); + Result.i = static_cast((s << 31) | (e << 23) | m); return Result.f; } - GLM_FUNC_QUALIFIER hdata toFloat16(float const & f) + GLM_FUNC_QUALIFIER hdata toFloat16(float const& f) { uif32 Entry; Entry.f = f; - int i = (int)Entry.i; + int i = static_cast(Entry.i); // // Our floating point number, f, is represented by the bit diff --git a/readme.md b/readme.md index f5181bc6b..e2d75ca3b 100644 --- a/readme.md +++ b/readme.md @@ -73,7 +73,8 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added FAQ 12: Windows headers cause build errors... #557 - Removed GCC shadow warnings #595 - Added error for including of different versions of GLM #619 -- Added GLM_FORCE_IGNORE_VERSION to ignore error caused by including different version of GLM #619 +- Added GLM_FORCE_IGNORE_VERSION to ignore error caused by including different version of GLM #619 +- Reduced warnings when using very strict compilation flags #646 #### Fixes: - Removed doxygen references to GTC_half_float which was removed in 0.9.4