mercredi 28 novembre 2018

Type aliasing rules with vectors/arrays

I know this is safe regarding type aliasing:

Foo foo;
char* buf = reinterpret_cast<char*>(foo);

What about:

std::vector<Foo> vvv;
auto buf = reinterpret_cast<std::vector<char> *>(vvv);
auto ptr = new Foo[50];
auto ptr_buf = reinterpret_cast<char *>(vvv);

I guess this is not allowed, am I correct? The standard says nothing about this in chapter 3.10 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf).

Aucun commentaire:

Enregistrer un commentaire