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.
This commit is contained in:
Krzesimir Nowak 2024-02-04 21:21:08 +01:00 committed by Christophe
parent 8ebe4b5e57
commit 38edba1818
14 changed files with 28 additions and 26 deletions

View File

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

View File

@ -219,14 +219,14 @@ namespace glm
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }

View File

@ -219,14 +219,14 @@ namespace glm
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }

View File

@ -221,14 +221,14 @@ namespace glm
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }

View File

@ -238,14 +238,14 @@ namespace glm
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }

View File

@ -240,14 +240,14 @@ namespace glm
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }

View File

@ -244,14 +244,14 @@ namespace glm
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }

View File

@ -257,14 +257,14 @@ namespace glm
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }

View File

@ -257,14 +257,14 @@ namespace glm
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }

View File

@ -288,14 +288,14 @@ namespace glm
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }
template<typename T, qualifier Q> 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 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]; return this->value[i];
} }

View File

@ -74,7 +74,7 @@ namespace detail
template<typename T, qualifier Q> template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & qua<T, Q>::operator[](typename qua<T, Q>::length_type i) 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 # ifdef GLM_FORCE_QUAT_DATA_WXYZ
return (&w)[i]; return (&w)[i];
# else # else
@ -85,7 +85,7 @@ namespace detail
template<typename T, qualifier Q> template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& qua<T, Q>::operator[](typename qua<T, Q>::length_type i) const 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 # ifdef GLM_FORCE_QUAT_DATA_WXYZ
return (&w)[i]; return (&w)[i];
# else # else

View File

@ -105,7 +105,7 @@ namespace glm
template<typename T, qualifier Q> template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i) 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) switch(i)
{ {
default: default:
@ -119,7 +119,7 @@ namespace glm
template<typename T, qualifier Q> 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 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) switch(i)
{ {
default: default:

View File

@ -169,7 +169,7 @@ namespace glm
template<typename T, qualifier Q> template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i) 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) switch(i)
{ {
default: default:
@ -185,7 +185,7 @@ namespace glm
template<typename T, qualifier Q> 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 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) switch(i)
{ {
default: default:

View File

@ -478,7 +478,7 @@ namespace detail
template<typename T, qualifier Q> template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i) 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) switch(i)
{ {
default: default:
@ -496,7 +496,7 @@ namespace detail
template<typename T, qualifier Q> 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 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) switch(i)
{ {
default: default: