http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46224
Summary: Enhancement: Issue warning when matching placement
delete operator is missing
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
Consider the appended sample program - it has a matching placement delete
operator which gets called since the corresponding new throws. When changing
the signature (either unintentional or simply by not providing such a matching
placement delete operator at all) of the placement delete operator a warning
should be issued such that the programmer sees that there is the danger of
memory not being freed.
VC++ issues a warning C4291 in those cases: "no matching operator delete found;
memory will not be freed if initialization throws an exception"
#include <iostream>
#include <new>
#include <cstdlib>
using namespace std;
#define MY_NEW new(__FILE__,__LINE__)
void* operator new(
std::size_t num_bytes,
const char*,
int) throw (std::bad_alloc)
{
return malloc(num_bytes);
}
void operator delete(
void*,
const char*,
int)
{
cout << "YES" << endl;
}
struct Foo
{
Foo() { throw int(); }
};
int main()
{
Foo* f;
try {
f = MY_NEW Foo();
}
catch (int&) {}
return 0;
}