The expression delete [] data must match the new T [] that created the array on the heap, so T is the data type * . Otherwise, the program behavior is undefined (5.3.5).
In your example, the data type and * data are unknown. If T is not char , the behavior is undefined.
You should not call delete [] data even after calling the destructors in a loop. It would be better to call delete [] reinterpret_cast <char *> (data) to avoid undefined behavior. Before freeing memory, type T destructors must be called.
source share