This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR 30457 Please warn about va_start(ap, invalid)
2008/8/12 Ian Lance Taylor <iant@google.com>:
> "Manuel López-Ibáñez" <lopezibanez@gmail.com> writes:
>
>> 2008/8/12 Ian Lance Taylor <iant@google.com>:
>>> "Manuel López-Ibáñez" <lopezibanez@gmail.com> writes:
>>>
>>>>> This doesn't look right to me. It looks to me like you will issue
>>>>> this warning whenever the parameter is declared with the register
>>>>> storage class. It's OK to use "register int".
>>>>>
>>>>
>>>> Then I do not understand what the standard is saying here. Could you
>>>> give me one example of each things that is undefined per that
>>>> paragraph, please?
>>>
>>> Gah, you're right, I misread it. Sorry.
>>>
>>
>> Anyway, I was not able to generate testcases for array types and function
>> types. Any idea?
>
> I don't think it's meant to be overly cryptic. This program invokes
> undefined behaviour.
>
> #include <stdarg.h>
> typedef void func_type();
> typedef int array_type[10];
> int
> foo(int a, ...)
> {
> va_list ap;
> int i;
> va_start (ap, a);
> va_arg (ap, func_type) ();
> i = va_arg (ap, array_type)[0];
> va_end (ap);
> return i;
> }
>
> gcc happens to handle it reasonably today, by decaying the types to
> pointer types when invoking va_arg. But it's still undefined.
Sorry to bother you again but the quoted passage from the standard is
talking about the type of 'a' (the second argument to va_start) not
the type passed to va_arg. So this testcase is not testing what the
standard is describing.
Cheers,
Manuel.