Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2022-02-18 17:21:19


Andrey Semashev wrote:
> >> alignas(int) unsigned char storage[sizeof(int)];
> >> int* p1 = new (storage) int(1);
> >> float* p2 = new (storage) float(2.0f);
> >> int* p3 = new (storage) int(3);
> >> std::printf("%d\n", *p1);
> >>
> >> the program is allowed to print 1...
> >
> > I don't think it is. The "will automatically apply to the new object"
> > clause applies (even in its C++14 form) and all its requirements seem to be
> met.
> > https://eel.is/c++draft/basic.life#8
>
> The requirement "o1 and o2 are of the same type" is not satisfied, as the types
> int and float are different.
>
> Yes, you eventually create an int in the same storage, but I don't see where the
> standard requires this exemption rule to work across creation of an object of
> an incompatible type.

Interesting interpretation. I don't see where it requires it to be invalidated by
the intermediate creation of the float, though. It says "after" but it doesn't
say "immediately after".


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk