C++ Logo

std-discussion

Advanced search

Re: Placement new into static storage violates strict pointer safety?

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Sat, 24 Aug 2019 02:00:41 +0300
[basic.stc] is known to be completely broken.

Consider:

 struct { int i; int j; } s;
 int main()
 {
  ::new(&s.j) int{};
 }

The newly-created int object is a subobject of `s` ([intro.object]/2)
Since it was created using new-expression, it has dynamic storage duration ([basic.stc]/2).
But [basic.stc.inherit]/1 says "The storage duration of subobjects and reference members is that of their complete object", so it has static storage duration.

Received on 2019-08-23 18:02:46