public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* g++ delete issue
@ 2004-04-06  3:57 Nilmoni Deb
  2004-04-08  2:22 ` Jim Wilson
  0 siblings, 1 reply; 3+ messages in thread
From: Nilmoni Deb @ 2004-04-06  3:57 UTC (permalink / raw)
  To: gcc-bugs

"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...




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: g++ delete issue
  2004-04-06  3:57 g++ delete issue Nilmoni Deb
@ 2004-04-08  2:22 ` Jim Wilson
  2004-04-08  3:42   ` Nilmoni Deb
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Wilson @ 2004-04-08  2:22 UTC (permalink / raw)
  To: Nilmoni Deb; +Cc: gcc-bugs

Nilmoni Deb wrote:
> 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 ?

In general, you will get better answers if you file bugs into our 
bugzilla bug database rather than sending email to gcc-bugs.  We don't 
track bugs sent via email.

I don't have a copy of the C++ standard, so I can't comment definitively 
on this.  However, I can note that in general it is not possible for the 
compiler to know how an object has been allocated in all cases.  The 
object might have been allocated in a different function for instance. 
There might be multiple assignments to the variable under different 
conditions, and it may not be obvious at compile time which one will 
reach the delete.  In such cases, language standards generally do not 
require any warning/error at all, even for relatively simple cases like 
this one.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: g++ delete issue
  2004-04-08  2:22 ` Jim Wilson
@ 2004-04-08  3:42   ` Nilmoni Deb
  0 siblings, 0 replies; 3+ messages in thread
From: Nilmoni Deb @ 2004-04-08  3:42 UTC (permalink / raw)
  To: Jim Wilson; +Cc: gcc-bugs


On Wed, 7 Apr 2004, Jim Wilson wrote:

> Nilmoni Deb wrote:
> > 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 ?
>
> In general, you will get better answers if you file bugs into our
> bugzilla bug database rather than sending email to gcc-bugs.  We don't
> track bugs sent via email.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14885

It will be nice if all future updates/opinions are posted to this bug
instead of directly emailing me.

> I don't have a copy of the C++ standard, so I can't comment definitively
> on this.  However, I can note that in general it is not possible for the
> compiler to know how an object has been allocated in all cases.  The
> object might have been allocated in a different function for instance.
> There might be multiple assignments to the variable under different
> conditions, and it may not be obvious at compile time which one will
> reach the delete.  In such cases, language standards generally do not
> require any warning/error at all, even for relatively simple cases like
> this one.
> --
> Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com
>
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-04-08  3:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-06  3:57 g++ delete issue Nilmoni Deb
2004-04-08  2:22 ` Jim Wilson
2004-04-08  3:42   ` Nilmoni Deb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).