Date: Thu, 9 May 2024 11:23:21 +0100
On Thu, 9 May 2024 at 11:22, Giuseppe D'Angelo via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Il 09/05/24 12:00, Frederick Virchanza Gotham via Std-Proposals ha scritto:
> >
> > Same size, same representation, same alignment. So you can do the
> following:
> >
> > char *Func(char *arg)
> > {
> > double*p1 = (double*)arg;
> > int*p2 = (int*)p1;
> > std::string*p3 = (std::string*)p2;
> > return (char*)p3;
> > }
> >
> > The above function would be well-formed with well-defined behaviour,
>
> Why should this code be well-formed? Strict aliasing is a thing, even in
> a world of intercompatible pointers.
>
There is no aliasing violation here, the pointer is never dereferenced, and
ends up with the original type.
std-proposals_at_[hidden]> wrote:
> Il 09/05/24 12:00, Frederick Virchanza Gotham via Std-Proposals ha scritto:
> >
> > Same size, same representation, same alignment. So you can do the
> following:
> >
> > char *Func(char *arg)
> > {
> > double*p1 = (double*)arg;
> > int*p2 = (int*)p1;
> > std::string*p3 = (std::string*)p2;
> > return (char*)p3;
> > }
> >
> > The above function would be well-formed with well-defined behaviour,
>
> Why should this code be well-formed? Strict aliasing is a thing, even in
> a world of intercompatible pointers.
>
There is no aliasing violation here, the pointer is never dereferenced, and
ends up with the original type.
Received on 2024-05-09 10:24:39