The delete[] operator loses support for objects with destructor

When the delete[] operator is called explicitly, the support for objects with specific destructor is lost due to the following complications: This code should throw an unhandled exception when it tries to shrink the array of B's because the cookie isn't handled correctly.




/* ncomputers.org */
#include<cstdlib>
#include<iostream>
using namespace std;

void*operator new[](size_t s){
    cout<<"Block size: "<<s<<endl;
    return malloc(s);
}
void operator delete[](void*p){
    free(p);
}
void operator delete[](void*p,size_t s){
    //It is required to know if the data type has a specific destructor to handle the cookie correctly.
    bool destructor=0;
    if(destructor){
        p=(char*)p-sizeof(size_t),s+=sizeof(size_t);
    }
    cout<<"New block size: "<<s<<endl;
    if(realloc(p,s)!=p)throw 0;
}

struct A{
    char a;

    A():a(0){}
    ~A()=default;
};

struct B{
    char b;

    B():b(0){}
    ~B(){}
};

int main(){
    unsigned S=10,s=4;
    cout<<"Creating "<<S<<" A's"<<endl;
    A*a=new A[S];
    cout<<"Creating "<<S<<" B's"<<endl;
    B*b=new B[S];
    cout<<"Shrinking A to "<<s<<" elements"<<endl;
    operator delete[](a,sizeof(A)*s);
    cout<<"Shrinking B to "<<s<<" elements"<<endl;
    operator delete[](b,sizeof(B)*s);
    cout<<"Deleting A and B"<<endl;
    delete[]b,delete[]a;
    return 0;
}