g-truc / glm

OpenGL Mathematics (GLM)
https://glm.g-truc.net
Other
9.05k stars 2.1k forks source link

Fix uninitialized in constexpr warning #1264

Open JBurnWork opened 6 months ago

JBurnWork commented 6 months ago

Matrix multiplication functions that were recently marked as 'constexpr' in commit '1cc8e80e3ba140239196d9a4597a2ea8139a4aa5' can throw warnings about an "uninitialized variable 'Result' in constexpr function".

Fix the issue by removing 'Result' and returning the calculated matrix. Only one matrix multiplication function per *.inl file used 'Result' as a variable, so this unifies how matrix multiplication functions are written.

JBurnWork commented 6 months ago

In GCC 9.4.0, this solves the following:


<snip>/glm/glm/detail/type_mat4x4.hpp:13:9: note: ‘struct glm::mat<4, 4, float, glm::packed_highp>’ has no user-provided default constructor
   13 |  struct mat<4, 4, T, Q>
      |         ^~~~~~~~~~~~~~~
<snip>/glm/detail/type_mat4x4.hpp:35:49: note: constructor is not user-provided because it is explicitly defaulted in the class body
   35 |   GLM_DEFAULTED_DEFAULT_CTOR_DECL GLM_CONSTEXPR mat() GLM_DEFAULT_CTOR;
      |                                                 ^~~
<snip>/glm/detail/type_vec4.hpp:68:14: note: and the implicitly-defined constructor does not initialize ‘float glm::vec<4, float, glm::packed_highp>::<unnamed union>::x’
   68 |    union { T x, r, s; };
      |              ^
JBurnWork commented 6 months ago

When using an 'arm-poky-linux-gnueabi-g++' ARM GNU toolchain for the TI-DRA746 processor, the error is the following:


<snip>/glm/glm/./ext/../detail/type_mat4x4.inl: In instantiation of ???constexpr glm::mat<4, 4, T, Q> glm::operator*(const glm::mat<4, 4, T, Q>&, const glm::mat<4, 4, T, Q>&) [with T = float; glm::qualifier Q = (glm::qualifier)0u]???:
<snip>/glm/glm/./ext/../detail/type_mat4x4.inl:642:19: error: uninitialized variable ???Result??? in ???constexpr??? function
14:28:28    mat<4, 4, T, Q> Result;
14:28:28                    ^~~~~~
14:28:28 In file included from <snip>/glm/glm/./ext/matrix_double4x4.hpp:5:0,
14:28:28                  from <snip>/glm/glm/mat4x4.hpp:5,
<snip>/glm/glm/./ext/../detail/type_mat4x4.hpp:13:9: note: ???struct glm::mat<4, 4, float, (glm::qualifier)0u>??? has no user-provided default constructor
14:28:28   struct mat<4, 4, T, Q>
14:28:28          ^~~~~~~~~~~~~~~
<snip>/glm/glm/./ext/../detail/type_mat4x4.hpp:35:49: note: constructor is not user-provided because it is explicitly defaulted in the class body
14:28:28    GLM_DEFAULTED_DEFAULT_CTOR_DECL GLM_CONSTEXPR mat() GLM_DEFAULT_CTOR;
14:28:28                                                  ^~~
14:28:28 In file included from <snip>/glm/glm/./ext/../detail/type_mat4x4.hpp:6:0,
14:28:28                  from <snip>/glm/glm/./ext/matrix_double4x4.hpp:5,
14:28:28                  from <snip>/glm/glm/mat4x4.hpp:5,
<snip>/glm/glm/./ext/../detail/type_vec4.hpp:68:14: note: and the implicitly-defined constructor does not initialize ???float glm::vec<4, float, (glm::qualifier)0u>::<anonymous union>::x???
14:28:28     union { T x, r, s; };
14:28:28               ^
DctrNoob commented 5 months ago

+1 for this PR

jdtech3 commented 5 months ago

+1 for this PR, this fixes compiling for Nios II as well.