This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Should structure with flexible array be allowed to be passed by value?
On Wed, Mar 25, 2009 at 6:37 AM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Wed, 25 Mar 2009, H.J. Lu wrote:
>
>> gcc.c-torture/compile/pr16566-2.c has
>>
>> ---
>> struct A
>> {
>> ? ? int i;
>> ? ? int x[];
>> };
>>
>> int foo(struct A a)
>> {
>> ? ? return (a,a).x[0];
>> }
>> ---
>>
>> foo will return a random number. I don't think it should be allowed.
>
> This is a perfectly ordinary case of accessing outside array bounds,
> undefined behavior at runtime if the code in question is ever executed but
> OK in a program as long as the dereference isn't executed.
Shouldn't gcc warn out of bound array access here?
--
H.J.