Other than deallocating memory, that is?
This testcase will either print nothing, or print "Failed", depending on how much inlining takes place. The replacement delete operator is treated as the usual deallocation function and is removed despite having an observable side-effect other than deallocation of memory.
Is the testcase correct, or is this a bug in LLVM?
--- new.cc ---
#include <new>
#include <cstdlib>
#include <cstddef>
#include <iostream>
using namespace std;
static bool global = false;
void* operator new(::size_t size) throw(bad_alloc) {
return ::malloc(size);
}
void operator delete(void *ptr) throw() {
global = true;
if (ptr != NULL)
::free(ptr);
}
int main(void) {
int *p = new int[2];
global = false;
delete p;
if (!global)
cout << "Failed\n";
}