This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/45821] no warning when returning a local variable address within a statement expression


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]