C++ Logo

std-discussion

Advanced search

Re: What is the meaning of `new T[0]`?

From: Brian Bi <bbi5291_at_[hidden]>
Date: Fri, 10 Sep 2021 15:44:34 -0400
Thanks. Too bad I can't see the reflector.

On Fri, Sep 10, 2021 at 3:42 PM language.lawyer--- via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> https://stackoverflow.com/a/60442328
>
> On 11/09/2021 00:11, Brian Bi via Std-Discussion wrote:
> > It's explicitly allowed to create an array with 0 elements using a
> > new-expression, but the standard doesn't seem to explain the meaning of
> the
> > returned pointer.
> >
> > As I see it, the most literal reading of the standard is the following:
> the
> > new-expression creates an array object with 0 elements. Because an object
> > can't have size 0, this empty array will have some nonzero
> > implementation-defined size. The pointer that's returned by the
> > new-expression points to this array. Since a pointer value is exactly one
> > of {null, pointer to object/function, pointer past the end, invalid}, and
> > this pointer does point to the array, it is not a past-the-end pointer.
> >
> > Perhaps it was intended for this pointer to be in the past-the-end
> > category, but the current wording doesn't seem clear enough.
> >
> >
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>


-- 
*Brian Bi*

Received on 2021-09-10 14:44:49