C++ Logo

std-discussion

Advanced search

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

From: Andrew Tomazos <andrewtomazos_at_[hidden]>
Date: Fri, 23 Aug 2019 21:49:01 -0700
On Fri, Aug 23, 2019 at 4:00 PM language.lawyer--- via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> [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)
>

How did you conclude that this is defined behaviour? What happens to the
old int subobject s.j? How did you conclude that the newly-created int
object is a subobject of the s object?



> 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.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

Received on 2019-08-23 23:51:18