This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/50476] Warn of pointer set to object whose lifetime is limited
- From: "manu at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 09 May 2012 11:05:39 +0000
- Subject: [Bug c/50476] Warn of pointer set to object whose lifetime is limited
- Auto-submitted: auto-generated
- References: <bug-50476-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50476
Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu.org
--- Comment #2 from Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> 2012-05-09 11:05:39 UTC ---
I think it is only undefined behaviour to access the pointer after the
life-time of y has finished, however, the following probably isn't, no?
void g()
{
...
*x = 2;
...
}
void f()
{
...
x = &y;
...
g();
...
x = NULL;
}
The C/C++ FE cannot distinguish between these two cases.
Do you have a suggestion about how to implement this?
I think it would require some kind of constant propagation to know that the
final value of x is safe, but no existing contributor is interested in
implementing such thing, so someone new has to step up and do the work.