This is the mail archive of the gcc-patches@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: PR 30457 Please warn about va_start(ap, invalid)


"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.

Ian


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