This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/19972] -Wreturn-local-addr misses return of local (nested) function pointer
- From: "egallager at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 24 Jul 2017 21:01:10 +0000
- Subject: [Bug c/19972] -Wreturn-local-addr misses return of local (nested) function pointer
- Auto-submitted: auto-generated
- References: <bug-19972-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19972
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2005-12-18 01:39:05 |2017-7-24
CC| |egallager at gcc dot gnu.org
Summary|Return Local (nested) |-Wreturn-local-addr misses
|function pointer |return of local (nested)
| |function pointer
--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Patrick Pelissier from comment #0)
> When returning local function pointer, it doesn't produce any warnings.
> For example:
>
> int *h() {
> int z;
> return &z;
> }
>
> int (*apply (int (*f) (const void *, const void *), void *a))(const void *)
> {
> int zozo(const void * b) { return f(a,b); };
> return &zozo;
> }
>
> Compile with -O2 -Wall, it produces a warning for h:
>
> ttt.c: In function 'h':
> ttt.c:17: warning: function returns address of local variable
>
With a newer gcc, this warning is now:
$ /usr/local/bin/gcc -c -O2 -Wall 19972.c
19972.c: In function ‘h’:
19972.c:3:9: warning: function returns address of local variable
[-Wreturn-local-addr]
return &z;
^~
Retitling this bug to better describe situation.