Skip to content

CWG2102 [expr.new] Clarify if the constructor needs to be accessible for a class type when using new T[0] #320

@ranaanoop

Description

@ranaanoop

Full name of submitter (unless configured in github; will be published with the issue): Anoop Rana

Reference (section label): [expr.new]

Link to reflector thread (if any): https://stackoverflow.com/questions/76307898/new-a0-initialization-of-zero-size-array-with-dynamic-storage-duration-for-a

Issue description:

It is not clear if the following program is well-formed or ill-formed according to the current wording.

class A {
    A()=delete;    
};

int main()
{
     auto ptr = new A[0];  
}

We see implementation divergence here. As per [expr.new]:

When the value of the expression is zero, the allocation function is called to allocate an array with no elements.

One possible interpretation of the above clause is that since the array doesn't have any elements, there is no need for any initialization and hence no need for the constructor to be accessible or to exist at all. This should be clarified. The intention seems that there is no need for the ctor to exist or be accessible.

Suggested resolution:

It should be clarified that whether the above behaves as if there is no initialization and so no need for accessible ctor etc or the constructor needs to be accessible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions