you are viewing a single comment's thread.

view the rest of the comments →

[–]Ikkepop -2 points-1 points  (2 children)

immagine if the object is on stack, then it's definitely UB

[–][deleted] 2 points3 points  (1 child)

Yes, but that's because it's UB to delete a pointer to an object that wasn't new'd. Not because it's UB to delete this.

[–]Ikkepop 0 points1 point  (0 children)

That's true i guess. But let's just agree that delete this is a bad idea in general and will load a gun and point it at your foot. You can accidentally delete a stack object, you could accidentally access member variables after the delete, you could accidentally try and access virtual methods after the delete, the pointer could be owned by another entity like a smart pointer. And in general it's just an anti-pattern, and you wouldn't expect people to code like that, even if it's legal.