[Bug c/45821] Missed -Wreturn-local-addr when local variable address comes from within a statement expression
egallager at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Oct 28 04:06:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45821
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Blocks| |90556
Summary|no warning when returning a |Missed -Wreturn-local-addr
|local variable address |when local variable address
|within a statement |comes from within a
|expression |statement expression
--- Comment #6 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Manuel López-Ibáñez from comment #4)
> (In reply to Andrew Gaul from comment #3)
> > int *function_return_local(void)
> > {
> > int x = 0;
> > return &x;
> > }
> >
> > int *statement_expression_return_local(void)
> > {
> > int *y = ({
> > int x = 0;
> > &x;
> > });
> > return y;
> > }
>
> We now warn at -O2:
>
> test.c:14:10: warning: function returns address of local variable
> [-Wreturn-local-addr]
> return y;
> ^
> test.c:11:11: note: declared here
> int x = 0;
> ^
>
> but only because we return y. For this testcase,
>
> int statement_expression_return_local(void)
> {
> int *y = ({
> int x = 0;
> &x;
> });
> return *y;
> }
>
> we get:
>
> test.c:14:10: warning: ‘x’ is used uninitialized in this function
> [-Wuninitialized]
> return *y;
> ^
>
> which is a bit confusing (and not the same warning).
It'd be good to get it from the same warning, so I'm making this block the
-Wreturn-local-addr meta-bug
>
> Possibly related to 60517.
> it would be good to add the testcase
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90556
[Bug 90556] [meta-bug] bogus/missing -Wreturn-local-addr
More information about the Gcc-bugs
mailing list