This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/45821] no warning when returning a local variable address within a statement expression
- From: "gcc at gaul dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 28 Sep 2010 17:51:22 +0000
- Subject: [Bug c/45821] no warning when returning a local variable address within a statement expression
- Auto-submitted: auto-generated
- References: <bug-45821-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45821
--- Comment #3 from Andrew Gaul <gcc at gaul dot org> 2010-09-28 17:51:21 UTC ---
The web form truncates all my attachedments at 244 bytes. Here is the source
inline:
/*
* GCC warns about returning a local variable address within a function but not
* within a statement expression:
*
* $ gcc statement_expression_return_local.c -c -Wall
* statement_expression_return_local.c: In function âfunction_return_localâ:
* statement_expression_return_local.c:13: warning: function returns address of
local variable
*/
int *function_return_local(void)
{
int x = 0;
return &x;
}
int *statement_expression_return_local(void)
{
int *y = ({
int x = 0;
&x;
});
return y;
}