[VC++ .NET 2003] BUG: operator delete[](void*, size_t) broken

From: Alberto Barbati (AlbertoBarbati_at_libero.it)
Date: 03/05/04


Date: Fri, 05 Mar 2004 11:41:14 GMT

Hi,

when operator delete[] is declared with two parameters void* and size_t,
the value of the second parameter should be the size of the allocated
block (12.5/5). This is incorrectly implemented in VC++ .NET 2003.

Given the following test program:

------------ Test.cpp
#include <iostream>

class Test
{
public:
        Test() {}
        ~Test() {}

        void* operator new[](std::size_t n)
        {
                std::cout << "new [" << n << "]\n";
                return ::operator new(n * 10);
        }

        void operator delete[](void* p, std::size_t n)
        {
                std::cout << "delete [" << n << "]\n";
                return ::operator delete(p);
        }

private:
        int a, b, c;
};

int main(int argc, char* argv[])
{
        Test* t = new Test[10];
        delete[] t;
}
------------ end Test.cpp

The output should be:

new [124]
delete [124]

(and that's exactly what I get with GCC 3.3.1). Instead VC++ gives:

new [124]
delete [12]

notice that the value of the second argument in delete[] is the size of
the class and not the size of the block.

Regards,

Alberto Barbati



Relevant Pages