Question Details

No question body available.

Tags

c++ language-lawyer buffer placement-new unsigned-char

Answers (1)

June 15, 2025 Score: 1 Rep: 103,644 Quality: Low Completeness: 70%

Question 1 - is it UB to pass a char array as an argument for placement new?

It's not UB by itself, but if that array can't "provide storage" (char array can't), then the array will have its lifetime ended because its storage got reused. Which is legal by itself, but since yours is an automatic variable, its automatic destruction at the end of scope might cause UB (I'm not 100% positive if trivial destruction does this).

See also: Why does the use of std::aligned_storage allegedly cause UB due to it failing to "provide storage"?.

Question 2 - if above is UB, is it so for automatic storage only, or also for heap-allocated storage?

Your example looks ok to me.