Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of defaulted operator= in vectors #791

Closed
dscharrer opened this issue Jul 20, 2018 · 2 comments
Closed

Removal of defaulted operator= in vectors #791

dscharrer opened this issue Jul 20, 2018 · 2 comments
Assignees
Milestone

Comments

@dscharrer
Copy link

dscharrer commented Jul 20, 2018

Commit 7ed97b4 removed the defaulted operator= from vector types and replaced it with a non-default implementation. This causes GCC 8's -Wclass-memaccess (enabled by -Wall) to (rightfully) complain when you try to memcpy anything containing a i.e. a glm::vec3.

Simple example:

#include <glm/glm.hpp>
#include <cstring>

int main() {
	glm::vec3 a = glm::vec3(0);
	glm::vec3 b;
	std::memcpy(&b, &a, sizeof(glm::vec3));
	return b[0];
}

Output with -Wall:

test.cpp: In function ‘int main()’:
test.cpp:10:39: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘glm::vec3’ {aka ‘struct glm::vec<3, float, (glm::qualifier)0>’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  std::memcpy(&b, &a, sizeof(glm::vec3));
                                       ^
In file included from /home/dscharrer/pro/build/deps/glm-git/glm/vec3.hpp:8,
                 from /home/dscharrer/pro/build/deps/glm-git/glm/glm.hpp:107,
                 from test.cpp:1:
/home/dscharrer/pro/build/deps/glm-git/glm/detail/type_vec3.hpp:17:9: note: ‘glm::vec3’ {aka ‘struct glm::vec<3, float, (glm::qualifier)0>’} declared here
  struct vec<3, T, Q>
         ^~~~~~~~~~~~

What was the problem with the previous implementation? It seems to work fine for vectors at least with GCC 4.8 and GCC 8 here.

@Groovounet
Copy link
Member

I was hiting some issues using defaulted contructors, const expressions and initializer lists with GCC...
Using memcpy with GLM types is a valid use case, I'll investigate how I can everything working together.

Thanks,
Christophe

@Groovounet
Copy link
Member

This issue is fixed in master branch for GLM 0.9.9.1 release.

Thanks for contributing,
Christophe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants