This is the mail archive of the gcc@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]

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.


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