steakhal wrote: > > I never understood the reasons of having metadata for placement-new. > > I don't think that there is any real reason for it, but I guess that some > compilers reused code from the code of non-placement new. > > > Certainly on linux it was not the case, but I'm skeptical if it was on any > > other platforms such as Windows. (prove me wrong). > > This (admittedly 16 years old) stackoverflow post claims that (at that time) > Visual Studio added four bytes of overhead to an array allocated with > placement new: > https://stackoverflow.com/questions/15254/can-placement-new-for-arrays-be-used-in-a-portable-way/75418614#75418614
Now I see. The link is wrong. It does not link to what you think, but there was a comment that suggests what you said. [Here](https://godbolt.org/z/8cWMMoWGr) is a slightly modified variant of that code, on some different msvc and clang 19. I didn't check the standard, but as I recall, one is only allowed to use the pointer returned by the placement new to manipulate the object, but then when we call `delete[]` we must us the pointer we had from `operator new[]`. Despite the pointers `pA` and `pBuffer` are equal, deleting the buffer using `pA` codegens to a segfault using clang, but when deleting via the `pBuffer` it works. Seeing this, we definitely have some UB in the example that clang sometimes exploits. And if we have UB, of course MSVC have freedom to do whatever it wants. https://github.com/llvm/llvm-project/pull/150161 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits