I am learning about placement-new in C++ using the books listed here. Now, to look at some examples, I came across the following snippet in one of the SO post that claims that it (the given example) has undefined behavior :
For example, this has UB:
void ub() { alignas(string) char buf[sizeof(string)]; // memory is allocated new(buf) string("1"); // string("1") is constructed } // memory is deallocated but string("1") outlives the memory!
As you can see the user claims that the above snippet has undefined behaviour. But I think that it has memory leak and not UB. Can someone tell me whether the above snippet has UB or memory leak or both and if my understanding (that it has memory leak but not UB) is correct or not.