This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Warn if making external references to local stack memory?
- From: Fredrik Hederstierna <fredrik dot hederstierna at securitas-direct dot com>
- To: gcc at gcc dot gnu dot org
- Cc: iant at google dot com
- Date: Tue, 10 Apr 2012 09:49:11 +0200
- Subject: Re: Warn if making external references to local stack memory?
- References:
>> GCC does warn if returning a pointer to a local variable (stack memory).
>> But there are alot of more cases where GCC could possibly warn,
>> eg. when references are made to local variables or stack memory.
>>
>> See this attached example code.
>> GCC warns for first case, but not the others.
>> I think all cases can be considered program bugs,
>> and could trigger a compiler warning I think.
>
> Thanks. I would encourage you to file an enhancement request at
> http://gcc.gnu.org/bugzilla/ .
>
>> I've found out that the present warning is done in "c-typeck.c",
>> is this the right place to but additional warnings of this kind too?
>
> Since these sorts of errors can occur in both C and C++ it would be
> slightly better to use a common framework for them if possible, perhaps
> in c-family/c-common.c. I haven't really thought about what is required
> here, though.
I've added the following enhancement request to bugzilla
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52923
"Bug?52923 - Warn if making external references to local stack memory"
Thanks & Best Regards
Fredrik