Can there be different implicit objects based on a later runtime decision in C++20?

后端 未结 1 776
孤独总比滥情好
孤独总比滥情好 2021-02-14 06:40

This question refers to the addition of P0593 to the latest C++20 draft .

Here is my example:

#include 
#include 

void foo(         


        
相关标签:
1条回答
  • 2021-02-14 07:08

    The implicit object creation is supposed to happen just once, at the point of malloc; it isn't triggered by the assignment statement in foo.

    That's not relevant. What matters is which object gets created. The standard says that the object which gets created is one which makes something which would have been UB into well-defined code:

    that operation implicitly creates and starts the lifetime of zero or more objects of implicit-lifetime types ([basic.types]) in its specified region of storage if doing so would result in the program having defined behavior.

    Behavior is ultimately based on runtime execution, not static analysis. So you need only follow the execution of the program until you run into a case where behavior would not be defined, yet would be defined if an object of some type had been created in that storage at the time of the operation in question.

    So the location of creation is always "the operation", but the determination of what gets created is based on how the memory gets used at runtime (ie: behavior).

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