Observable behavior and undefined behavior — What happens if I don't call a destructor?

后端 未结 13 2576
滥情空心
滥情空心 2020-12-03 06:48

Note: I\'ve seen similar questions, but none of the answers are precise enough, so I\'m asking this myself.

This is a very nitpicky "language-lawye

相关标签:
13条回答
  • 2020-12-03 07:53

    I have not read everyone else's input, but I have a simple explanation. In the quote

    however, if there is no explicit call to the destructor or if a delete-expression is not used to release the storage, the destructor shall not be implicitly called and any program that depends on the side effects produced by the destructor has undefined behavior.

    The meaning is very different depending on how you parse it. This meaning is what I hear people talking about.

    however, { if there is no explicit call to the destructor or if a delete-expression is not used to release the storage }, the destructor shall not be implicitly called and any program that depends on the side effects produced by the destructor has undefined behavior.

    But I think this meaning makes more sense

    however, if there is no explicit call to the destructor or { if a delete-expression is not used to release the storage, the destructor shall not be implicitly called and any program that depends on the side effects produced by the destructor has undefined behavior } .

    which basically says C++ does not have a garbage collector and if you assume it does have GC your program will not work as you expect.

    0 讨论(0)
提交回复
热议问题