8000
Skip to content

Removal of defaulted operator= in vectors #791

@dscharrer

Description

@dscharrer

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0