g++ delete issue
Nilmoni Deb
ndeb@ece.cmu.edu
Tue Apr 6 03:57:00 GMT 2004
"gcc -v"
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.3.1/specs
Configured with: ../configure --prefix=/usr --libdir=/usr/lib
--with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info
--enable-shared --enable-threads=posix --disable-checking
--enable-long-long --enable-__cxa_atexit
--enable-languages=c,c++,ada,f77,objc,java,pascal
--host=i586-mandrake-linux-gnu --with-system-zlib
Thread model: posix
gcc version 3.3.1 (Mandrake Linux 9.2 3.3.1-2mdk)
The following C++ program compiles ok without any warning, when I use
"g++ -g file.cpp" .
#include <iostream>
using namespace std;
int main()
{
int u=3;
cout << "u = " << u << endl;
delete &u;
return 0;
}
During runtime, the program segmentation faults after printing the value
of u. The culprit is obviously the "delete" statement.
My concern is that the compiler allows the explicit "delete &u"
operation even though the variable u is not user allocated. Should
the compiler be expected to give a warning/error message when such a
statement appears ?
thanks...
More information about the Gcc-bugs
mailing list