https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118262
Bug ID: 118262 Summary: gcc does not error on inaccessible potentially invoked destructor on dynamic initialization of an object array Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: accepts-invalid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rush102333 at gmail dot com Target Milestone: --- Hello! I have submitted an issue on the bug tracker of LLVM but it ends up more like a bug of GCC. I'm now trying to report it again: The test code: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class S { ~S()=default; }; int main(){ S *ss = new S[100]; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCC accepts it but there seem to be some problems according to the corresponding standard: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ https://eel.is/c++draft/expr.new#26 If the new-expression creates an array of objects of class type, the destructor is potentially invoked ([class.dtor]). https://eel.is/c++draft/class.dtor#14.sentence-7 A program is ill-formed if a destructor that is potentially invoked is deleted or not accessible from the context of the invocation. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please note that gcc rejects the code if '~S()' is not defaulted: https://godbolt.org/z/GW55zs6fW Please see https://github.com/llvm/llvm-project/issues/121319 for the complete discussion.