I believe this technically creates UB, although it is a form of UB that will probably never cause a visible side effect (it uses new []
, but I believe it will be consistent with delete
- but for char
it usually will not cause visible Problems).
IMO, it's almost worse than using a new expression to highlight what should really be raw bytes instead of objects. If I did this, I would write it like this:
void *a::operator new (size_t l,int n) { return ::operator new(l+ (n>1 ? n - 1 : 0)*sizeof(double)); }
You will agree with this:
void a::operator delete(void *block) { ::operator delete(block); }
source share