So gcc 4.9.0
has implemented a static_assert
ion that the type is not void
to be correctly conforming to the standard. Which is great, all for standards conformance.
I have a variant type that stored the data under a std::unique_ptr<void>
which now doesn't work. The easy fix is to just change it to a std::shared_ptr<void>
and it compiles straight away. The better fix is to provide the deleter functor.
Is the following a safe way of fixing up the unique_ptr
? Will this exhibit undefined behaviour with certain polymorphic types?
#include <memory>
#include <iostream>
template<typename T>
void Deleter(void * p) {
delete reinterpret_cast<T*>(p);
}
int main() {
const std::unique_ptr<void, void(*)(void*)> v(new int(199), Deleter<int>);
std::cout << *reinterpret_cast<int*>(v.get()) << std::endl;
return 0;
}