Open xmh0511 opened 1 year ago
Related to CWG2514. A possible resolution is making new-expressions never create a complete object of a cv-qualified type (while keeping the type of new-expressions).
A possible resolution is making new-expressions never create a complete object of a cv-qualified type (while keeping the type of new-expressions).
This would introduce another issue: whether such two objects are pointer-interconvertible or not.
This would introduce another issue: whether such two objects are pointer-interconvertible or not.
They are probably not, which is status quo. But it seems that [basic.life] p8 provides stronger guarantees than those of pointer-interconvertibility.
Perhaps it would be better to additionally specify the following (which seemingly belongs to another issue)?
o1 and o2 are considered to be the same object for the purpose of pointer-interconvertibility ([basic.compound]).
What exactly is the defect here?
I think the analysis for the original example is correct, and that's what the rules of the language are.
Full name of submitter (unless configured in github; will be published with the issue): Jim X
[basic.life] p8 says:
Consider this example:
After
#1
,a
refers to a const objecto1
, after#2
,o1
has its lifetime ended and sinceo1
is not transparently replaceable witho2
( an object ofint
) according to the above bullet,a
can never automatically refer to the new created object. The subsequent access toa
results in UB.