sparsepp
sparsepp copied to clipboard
Compiler warning on realloc call within sparsepp.
Hi @greg7mdp,
Thanks again for both sparsepp and parallel-hashmap! I wanted to report a (fairly verbose) compiler warning I get when using sparsepp within some of our code. Specifically, I get a a compiler trace that ends in the following warning. It looks like the root cause is using realloc on a type that is not trivially copyable. Any suggestions on how to fix this?
sparsepp/spp_utils.h:425:51: warning: 'void* realloc(void*, size_t)' moving an object of non-trivially copyable type 'struct std::pair<const std::pair<unsigned int, unsigned int>, unsigned int>'; use 'new' and 'delete' instead [-Wclass-memaccess]
425 | pointer res = static_cast<pointer>(realloc(p, new_size * sizeof(T)));
Hi @rob-p,
Thanks for the kind words!
This type struct std::pair<const std::pair<unsigned int, unsigned int>, unsigned int> is in fact safe to reallocate, even if the c++11 API std::is_trivially_copyable returns false. sparsepp doesn't require a c++11 compiler and uses the internal spp::is_relocatable.
As far as I can tell this warning can safely be ignored.