Avoid warnings about comparisons being always true

Depending on the signedness of length_t type we may either get
warnings comparison of unsigned expression in ‘>= 0’ being always true
or do insufficient checking by not checking if index is not negative.

Hide the index checking behind a macro that check the index properly.
master
Krzesimir Nowak ago%!(EXTRA string=1 year) committed by Christophe
parent 8ebe4b5e57
commit 38edba1818
  1. 2
      glm/detail/setup.hpp
  2. 4
      glm/detail/type_mat2x2.inl
  3. 4
      glm/detail/type_mat2x3.inl
  4. 4
      glm/detail/type_mat2x4.inl
  5. 4
      glm/detail/type_mat3x2.inl
  6. 4
      glm/detail/type_mat3x3.inl
  7. 4
      glm/detail/type_mat3x4.inl
  8. 4
      glm/detail/type_mat4x2.inl
  9. 4
      glm/detail/type_mat4x3.inl
  10. 4
      glm/detail/type_mat4x4.inl
  11. 4
      glm/detail/type_quat.inl
  12. 4
      glm/detail/type_vec2.inl
  13. 4
      glm/detail/type_vec3.inl
  14. 4
      glm/detail/type_vec4.inl

@ -614,8 +614,10 @@
#ifdef GLM_FORCE_SIZE_T_LENGTH
# define GLM_CONFIG_LENGTH_TYPE GLM_LENGTH_SIZE_T
# define GLM_ASSERT_LENGTH(l, max) (assert ((l) < (max)))
#else
# define GLM_CONFIG_LENGTH_TYPE GLM_LENGTH_INT
# define GLM_ASSERT_LENGTH(l, max) (assert ((l) >= 0 && (l) < (max)))
#endif
namespace glm

@ -219,14 +219,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 2, T, Q>::col_type& mat<2, 2, T, Q>::operator[](typename mat<2, 2, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 2, T, Q>::col_type const& mat<2, 2, T, Q>::operator[](typename mat<2, 2, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

@ -219,14 +219,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 3, T, Q>::col_type & mat<2, 3, T, Q>::operator[](typename mat<2, 3, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 3, T, Q>::col_type const& mat<2, 3, T, Q>::operator[](typename mat<2, 3, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

@ -221,14 +221,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 4, T, Q>::col_type & mat<2, 4, T, Q>::operator[](typename mat<2, 4, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 4, T, Q>::col_type const& mat<2, 4, T, Q>::operator[](typename mat<2, 4, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

@ -238,14 +238,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 2, T, Q>::col_type & mat<3, 2, T, Q>::operator[](typename mat<3, 2, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 2, T, Q>::col_type const& mat<3, 2, T, Q>::operator[](typename mat<3, 2, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

@ -240,14 +240,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 3, T, Q>::col_type & mat<3, 3, T, Q>::operator[](typename mat<3, 3, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 3, T, Q>::col_type const& mat<3, 3, T, Q>::operator[](typename mat<3, 3, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

@ -244,14 +244,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 4, T, Q>::col_type & mat<3, 4, T, Q>::operator[](typename mat<3, 4, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 4, T, Q>::col_type const& mat<3, 4, T, Q>::operator[](typename mat<3, 4, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

@ -257,14 +257,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 2, T, Q>::col_type & mat<4, 2, T, Q>::operator[](typename mat<4, 2, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 2, T, Q>::col_type const& mat<4, 2, T, Q>::operator[](typename mat<4, 2, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

@ -257,14 +257,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 3, T, Q>::col_type & mat<4, 3, T, Q>::operator[](typename mat<4, 3, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 3, T, Q>::col_type const& mat<4, 3, T, Q>::operator[](typename mat<4, 3, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

@ -288,14 +288,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 4, T, Q>::col_type & mat<4, 4, T, Q>::operator[](typename mat<4, 4, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 4, T, Q>::col_type const& mat<4, 4, T, Q>::operator[](typename mat<4, 4, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

@ -74,7 +74,7 @@ namespace detail
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & qua<T, Q>::operator[](typename qua<T, Q>::length_type i)
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
return (&w)[i];
# else
@ -85,7 +85,7 @@ namespace detail
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& qua<T, Q>::operator[](typename qua<T, Q>::length_type i) const
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
return (&w)[i];
# else

@ -105,7 +105,7 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i)
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
@ -119,7 +119,7 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i) const
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:

@ -169,7 +169,7 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i)
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
@ -185,7 +185,7 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i) const
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:

@ -478,7 +478,7 @@ namespace detail
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i)
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
@ -496,7 +496,7 @@ namespace detail
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i) const
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:

Loading…
Cancel
Save