Skip to content

[clang] Dynamic initialization of an array of objects with a private destructor is rejected by clang #121319

@Rush10233

Description

@Rush10233

Very surprised to see that:

class S {
  ~S()=default;
};


int main(){
    S *ss = new S[100];
}

This is rejected by clang:

<source>:7:17: error: temporary of type 'S' has private destructor
    7 |     S *ss = new S[100];
      |                 ^
<source>:2:3: note: implicitly declared private here
    2 |   ~S()=default;
      |   ^

I wonder if I have missed some instructions on the standard, but it appears that other compilers including GCC, MSVC and EDG can normally accept it.

https://godbolt.org/z/9d6Y5b3Mr

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:edgDoes the clang frontend diverge from edg compiler on this issuediverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions