diff --git a/glm/detail/type_vec1.inl b/glm/detail/type_vec1.inl index 9f971501..30fe5036 100644 --- a/glm/detail/type_vec1.inl +++ b/glm/detail/type_vec1.inl @@ -61,14 +61,14 @@ namespace glm // -- Component accesses -- template - GLM_FUNC_QUALIFIER T & vec<1, T, Q>::operator[](typename vec<1, T, Q>::length_type i) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<1, T, Q>::operator[](typename vec<1, T, Q>::length_type i) { assert(i >= 0 && i < this->length()); return (&x)[i]; } template - GLM_FUNC_QUALIFIER T const& vec<1, T, Q>::operator[](typename vec<1, T, Q>::length_type i) const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<1, T, Q>::operator[](typename vec<1, T, Q>::length_type i) const { assert(i >= 0 && i < this->length()); return (&x)[i]; diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index dbd9fc25..73dc941d 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -60,7 +60,7 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 2;} - GLM_FUNC_DECL T& operator[](length_type i); + GLM_FUNC_DECL GLM_CONSTEXPR T& operator[](length_type i); GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const; // -- Implicit basic constructors -- @@ -114,10 +114,10 @@ namespace glm // -- Unary arithmetic operators -- - GLM_FUNC_DECL vec<2, T, Q> & operator=(vec const& v) GLM_DEFAULT; + GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> & operator=(vec const& v) GLM_DEFAULT; template - GLM_FUNC_DECL vec<2, T, Q> & operator=(vec<2, U, Q> const& v); + GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> & operator=(vec<2, U, Q> const& v); template GLM_FUNC_DECL vec<2, T, Q> & operator+=(U scalar); template @@ -193,27 +193,27 @@ namespace glm // -- Unary operators -- template - GLM_FUNC_DECL vec<2, T, Q> operator+(vec<2, T, Q> const& v); + GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v); template - GLM_FUNC_DECL vec<2, T, Q> operator-(vec<2, T, Q> const& v); + GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator-(vec<2, T, Q> const& v); // -- Binary operators -- template - GLM_FUNC_DECL vec<2, T, Q> operator+(vec<2, T, Q> const& v, T scalar); + GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v, T scalar); template - GLM_FUNC_DECL vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2); + GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2); template - GLM_FUNC_DECL vec<2, T, Q> operator+(T scalar, vec<2, T, Q> const& v); + GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(T scalar, vec<2, T, Q> const& v); template - GLM_FUNC_DECL vec<2, T, Q> operator+(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2); + GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2); template - GLM_FUNC_DECL vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2); + GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2); template GLM_FUNC_DECL vec<2, T, Q> operator-(vec<2, T, Q> const& v, T scalar); diff --git a/glm/detail/type_vec2.inl b/glm/detail/type_vec2.inl index d1727a3e..4a0fe4d1 100644 --- a/glm/detail/type_vec2.inl +++ b/glm/detail/type_vec2.inl @@ -102,7 +102,7 @@ namespace glm // -- Component accesses -- template - GLM_FUNC_QUALIFIER 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()); return (&x)[i]; @@ -119,7 +119,7 @@ namespace glm # if GLM_USE_DEFAULTED_FUNCTIONS == GLM_DISABLE template - GLM_FUNC_QUALIFIER vec<2, T, Q> & vec<2, T, Q>::operator=(vec<2, T, Q> const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> & vec<2, T, Q>::operator=(vec<2, T, Q> const& v) { this->x = v.x; this->y = v.y; @@ -129,7 +129,7 @@ namespace glm template template - GLM_FUNC_QUALIFIER vec<2, T, Q> & vec<2, T, Q>::operator=(vec<2, U, Q> const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> & vec<2, T, Q>::operator=(vec<2, U, Q> const& v) { this->x = static_cast(v.x); this->y = static_cast(v.y); @@ -445,13 +445,13 @@ namespace glm // -- Unary arithmetic operators -- template - GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<2, T, Q> const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v) { return v; } template - GLM_FUNC_QUALIFIER vec<2, T, Q> operator-(vec<2, T, Q> const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator-(vec<2, T, Q> const& v) { return vec<2, T, Q>( -v.x, @@ -461,7 +461,7 @@ namespace glm // -- Binary arithmetic operators -- template - GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<2, T, Q> const& v, T scalar) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v, T scalar) { return vec<2, T, Q>( v.x + scalar, @@ -469,7 +469,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2) { return vec<2, T, Q>( v1.x + v2.x, @@ -477,7 +477,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(T scalar, vec<2, T, Q> const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(T scalar, vec<2, T, Q> const& v) { return vec<2, T, Q>( scalar + v.x, @@ -485,7 +485,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2) { return vec<2, T, Q>( v1.x + v2.x, @@ -493,7 +493,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2) { return vec<2, T, Q>( v1.x + v2.x, diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index 8fd8699f..58b35c67 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -61,7 +61,7 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 3;} - GLM_FUNC_DECL T & operator[](length_type i); + GLM_FUNC_DECL GLM_CONSTEXPR T & operator[](length_type i); GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const; // -- Implicit basic constructors -- diff --git a/glm/detail/type_vec3.inl b/glm/detail/type_vec3.inl index ca9707a9..f66e0911 100644 --- a/glm/detail/type_vec3.inl +++ b/glm/detail/type_vec3.inl @@ -164,7 +164,7 @@ namespace glm // -- Component accesses -- template - GLM_FUNC_QUALIFIER 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()); return (&x)[i]; diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index d60ccdc6..7f2f5077 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -62,7 +62,7 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;} - GLM_FUNC_DECL T & operator[](length_type i); + GLM_FUNC_DECL GLM_CONSTEXPR T & operator[](length_type i); GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const; // -- Implicit basic constructors -- diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 2565d547..8208c44b 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -503,7 +503,7 @@ namespace detail // -- Component accesses -- template - GLM_FUNC_QUALIFIER 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()); return (&x)[i]; diff --git a/glm/ext/vec1.hpp b/glm/ext/vec1.hpp index 927fc52e..ef3659ed 100644 --- a/glm/ext/vec1.hpp +++ b/glm/ext/vec1.hpp @@ -78,8 +78,8 @@ namespace glm typedef length_t length_type; GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 1;} - GLM_FUNC_DECL T & operator[](length_type i); - GLM_FUNC_DECL T const& operator[](length_type i) const; + GLM_FUNC_DECL GLM_CONSTEXPR T & operator[](length_type i); + GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const; // -- Implicit basic constructors -- diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 2d65dea0..ca73c55d 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -56,7 +56,7 @@ namespace glm /// Return the count of components of a quaternion GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;} - GLM_FUNC_DECL T & operator[](length_type i); + GLM_FUNC_DECL GLM_CONSTEXPR T & operator[](length_type i); GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const; // -- Implicit basic constructors -- diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index d7b01a09..0c08d643 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -75,7 +75,7 @@ namespace detail // -- Component accesses -- template - GLM_FUNC_QUALIFIER T & tquat::operator[](typename tquat::length_type i) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & tquat::operator[](typename tquat::length_type i) { assert(i >= 0 && i < this->length()); return (&x)[i]; diff --git a/test/core/core_cpp_constexpr.cpp b/test/core/core_cpp_constexpr.cpp index c8d07e6c..35c56efe 100644 --- a/test/core/core_cpp_constexpr.cpp +++ b/test/core/core_cpp_constexpr.cpp @@ -31,6 +31,8 @@ static int test_vec1() } { + constexpr glm::ivec1 A(1); + static_assert(A[0] == 1, "GLM: Failed constexpr"); static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr"); static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr"); } @@ -85,6 +87,8 @@ static int test_vec2() } { + constexpr glm::ivec2 A(1); + static_assert(A[0] == 1, "GLM: Failed constexpr"); static_assert(glm::vec2(1.0f).x > 0.0f, "GLM: Failed constexpr"); static_assert(glm::vec2(1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr"); static_assert(glm::vec2(1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr"); @@ -100,6 +104,13 @@ static int test_vec2() static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr"); } + { + constexpr glm::ivec2 A(1); + constexpr glm::ivec2 B = A + 1; + constexpr glm::ivec2 C(3); + static_assert(A + B == C, "GLM: Failed constexpr"); + } + return Error; } @@ -161,6 +172,8 @@ static int test_vec3() } { + constexpr glm::ivec3 const A(1); + static_assert(A[0] == 1, "GLM: Failed constexpr"); static_assert(glm::vec3(1.0f).x > 0.0f, "GLM: Failed constexpr"); static_assert(glm::vec3(1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr"); static_assert(glm::vec3(1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr"); @@ -215,6 +228,8 @@ static int test_vec4() } { + constexpr glm::ivec4 A(1); + static_assert(A[0] == 1, "GLM: Failed constexpr"); static_assert(glm::ivec4(1).x > 0, "GLM: Failed constexpr"); static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).x > 0, "GLM: Failed constexpr"); static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).y < 0, "GLM: Failed constexpr"); @@ -244,6 +259,7 @@ static int test_quat() glm::quat constexpr Q = glm::identity(); static_assert(Q.x - glm::quat(1.0f, glm::vec3(0.0f)).x <= glm::epsilon(), "GLM: Failed constexpr"); + static_assert(Q[0] == 0, "GLM: Failed constexpr"); } return Error;