Skip to content

Commit

Permalink
GCC: Fix noexcept warnings on hash functions
Browse files Browse the repository at this point in the history
Fix warnings on hash functions with GCC and -Wnoexcept:
* Add GLM_HAS_NOEXCEPT flag & GLM_NOEXCEPT #define to setup.hpp.
* Add GLM_NOEXCEPT to hash functions in hash.hpp.
* Add GLM_NOEXCEPT to matrix operator[] accessors.
* Add gtx_hash.cpp and a test to verify all hash overloads compile.
  Configure with -DCMAKE_CXX_FLAGS="-Werror -Wnoexcept" to test.
  • Loading branch information
genpfault committed Aug 24, 2022
1 parent cc98465 commit 4b6284e
Show file tree
Hide file tree
Showing 23 changed files with 134 additions and 66 deletions.
12 changes: 12 additions & 0 deletions glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@
# define GLM_HAS_BITSCAN_WINDOWS 0
#endif

#if GLM_LANG & GLM_LANG_CXX11_FLAG
# define GLM_HAS_NOEXCEPT 1
#else
# define GLM_HAS_NOEXCEPT 0
#endif

#if GLM_HAS_NOEXCEPT
# define GLM_NOEXCEPT noexcept
#else
# define GLM_NOEXCEPT
#endif

///////////////////////////////////////////////////////////////////////////////////
// OpenMP
#ifdef _OPENMP
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace glm
typedef length_t length_type;
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 2; }

GLM_FUNC_DECL col_type & operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const;
GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT;
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT;

// -- Constructors --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ namespace glm
// -- Accesses --

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename mat<2, 2, T, Q>::col_type& mat<2, 2, T, Q>::operator[](typename mat<2, 2, T, Q>::length_type i)
GLM_FUNC_QUALIFIER 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());
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_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());
return this->value[i];
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace glm
typedef length_t length_type;
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 2; }

GLM_FUNC_DECL col_type & operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const;
GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT;
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT;

// -- Constructors --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ namespace glm
// -- Accesses --

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename mat<2, 3, T, Q>::col_type & mat<2, 3, T, Q>::operator[](typename mat<2, 3, T, Q>::length_type i)
GLM_FUNC_QUALIFIER 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());
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_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());
return this->value[i];
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace glm
typedef length_t length_type;
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 2; }

GLM_FUNC_DECL col_type & operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const;
GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT;
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT;

// -- Constructors --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x4.inl
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ namespace glm
// -- Accesses --

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename mat<2, 4, T, Q>::col_type & mat<2, 4, T, Q>::operator[](typename mat<2, 4, T, Q>::length_type i)
GLM_FUNC_QUALIFIER 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());
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_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());
return this->value[i];
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat3x2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace glm
typedef length_t length_type;
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 3; }

GLM_FUNC_DECL col_type & operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const;
GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT;
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT;

// -- Constructors --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat3x2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ namespace glm
// -- Accesses --

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename mat<3, 2, T, Q>::col_type & mat<3, 2, T, Q>::operator[](typename mat<3, 2, T, Q>::length_type i)
GLM_FUNC_QUALIFIER 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());
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_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());
return this->value[i];
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat3x3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace glm
typedef length_t length_type;
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 3; }

GLM_FUNC_DECL col_type & operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const;
GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT;
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT;

// -- Constructors --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat3x3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ namespace glm
// -- Accesses --

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename mat<3, 3, T, Q>::col_type & mat<3, 3, T, Q>::operator[](typename mat<3, 3, T, Q>::length_type i)
GLM_FUNC_QUALIFIER 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());
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_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());
return this->value[i];
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat3x4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace glm
typedef length_t length_type;
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 3; }

GLM_FUNC_DECL col_type & operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const;
GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT;
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT;

// -- Constructors --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat3x4.inl
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ namespace glm
// -- Accesses --

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename mat<3, 4, T, Q>::col_type & mat<3, 4, T, Q>::operator[](typename mat<3, 4, T, Q>::length_type i)
GLM_FUNC_QUALIFIER 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());
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_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());
return this->value[i];
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat4x2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace glm
typedef length_t length_type;
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 4; }

GLM_FUNC_DECL col_type & operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const;
GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT;
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT;

// -- Constructors --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat4x2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ namespace glm
// -- Accesses --

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename mat<4, 2, T, Q>::col_type & mat<4, 2, T, Q>::operator[](typename mat<4, 2, T, Q>::length_type i)
GLM_FUNC_QUALIFIER 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());
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_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());
return this->value[i];
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat4x3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace glm
typedef length_t length_type;
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 4; }

GLM_FUNC_DECL col_type & operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const;
GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT;
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT;

// -- Constructors --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat4x3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ namespace glm
// -- Accesses --

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename mat<4, 3, T, Q>::col_type & mat<4, 3, T, Q>::operator[](typename mat<4, 3, T, Q>::length_type i)
GLM_FUNC_QUALIFIER 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());
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_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());
return this->value[i];
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat4x4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace glm
typedef length_t length_type;
GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;}

GLM_FUNC_DECL col_type & operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const;
GLM_FUNC_DECL col_type & operator[](length_type i) GLM_NOEXCEPT;
GLM_FUNC_DECL GLM_CONSTEXPR col_type const& operator[](length_type i) const GLM_NOEXCEPT;

// -- Constructors --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat4x4.inl
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ namespace glm
// -- Accesses --

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename mat<4, 4, T, Q>::col_type & mat<4, 4, T, Q>::operator[](typename mat<4, 4, T, Q>::length_type i)
GLM_FUNC_QUALIFIER 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());
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_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());
return this->value[i];
Expand Down
30 changes: 15 additions & 15 deletions glm/gtx/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,91 +51,91 @@ namespace std
template<typename T, glm::qualifier Q>
struct hash<glm::vec<1, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::vec<1, T, Q> const& v) const;
GLM_FUNC_DECL size_t operator()(glm::vec<1, T, Q> const& v) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::vec<2, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::vec<2, T, Q> const& v) const;
GLM_FUNC_DECL size_t operator()(glm::vec<2, T, Q> const& v) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::vec<3, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::vec<3, T, Q> const& v) const;
GLM_FUNC_DECL size_t operator()(glm::vec<3, T, Q> const& v) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::vec<4, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::vec<4, T, Q> const& v) const;
GLM_FUNC_DECL size_t operator()(glm::vec<4, T, Q> const& v) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::qua<T,Q>>
{
GLM_FUNC_DECL size_t operator()(glm::qua<T, Q> const& q) const;
GLM_FUNC_DECL size_t operator()(glm::qua<T, Q> const& q) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::tdualquat<T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::tdualquat<T,Q> const& q) const;
GLM_FUNC_DECL size_t operator()(glm::tdualquat<T,Q> const& q) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::mat<2, 2, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<2, 2, T,Q> const& m) const;
GLM_FUNC_DECL size_t operator()(glm::mat<2, 2, T,Q> const& m) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::mat<2, 3, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<2, 3, T,Q> const& m) const;
GLM_FUNC_DECL size_t operator()(glm::mat<2, 3, T,Q> const& m) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::mat<2, 4, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<2, 4, T,Q> const& m) const;
GLM_FUNC_DECL size_t operator()(glm::mat<2, 4, T,Q> const& m) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::mat<3, 2, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<3, 2, T,Q> const& m) const;
GLM_FUNC_DECL size_t operator()(glm::mat<3, 2, T,Q> const& m) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::mat<3, 3, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<3, 3, T,Q> const& m) const;
GLM_FUNC_DECL size_t operator()(glm::mat<3, 3, T,Q> const& m) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::mat<3, 4, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<3, 4, T,Q> const& m) const;
GLM_FUNC_DECL size_t operator()(glm::mat<3, 4, T,Q> const& m) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::mat<4, 2, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<4, 2, T,Q> const& m) const;
GLM_FUNC_DECL size_t operator()(glm::mat<4, 2, T,Q> const& m) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::mat<4, 3, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<4, 3, T,Q> const& m) const;
GLM_FUNC_DECL size_t operator()(glm::mat<4, 3, T,Q> const& m) const GLM_NOEXCEPT;
};

template<typename T, glm::qualifier Q>
struct hash<glm::mat<4, 4, T,Q> >
{
GLM_FUNC_DECL size_t operator()(glm::mat<4, 4, T,Q> const& m) const;
GLM_FUNC_DECL size_t operator()(glm::mat<4, 4, T,Q> const& m) const GLM_NOEXCEPT;
};
} // namespace std

Expand Down
Loading

0 comments on commit 4b6284e

Please sign in to comment.