-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed as duplicate of#67405
Closed as duplicate of#67405
Copy link
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issueDoes the clang frontend diverge from gcc on this issueduplicateResolved as duplicateResolved as duplicate
Description
Hello Clang maintainers,
If the delete operator in a class is explicitly deleted, the class cannot be created on the heap.
The following code cannot be compiled with Clang, but it ca be compiled with GCC.
#include <cstddef>
#include <cstdlib>
class TestClass {
public:
void* operator new(std::size_t count) {
return malloc(count);
}
void operator delete(void* p) = delete;
void operator delete [](void* p) = delete;
};
int main(void)
{
TestClass *test = new TestClass();
return 0;
}
Please see this Compiler Explorer:
The is the error shown in the compiler explorer.
<source>:17:23: error: attempt to use a deleted function
17 | TestClass *test = new TestClass();
| ^
<source>:10:9: note: 'operator delete' has been explicitly marked deleted here
10 | void operator delete(void* p) = delete;
| ^
1 error generated.
Compiler returned: 1
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issueDoes the clang frontend diverge from gcc on this issueduplicateResolved as duplicateResolved as duplicate