[cfe-commits] r72689 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaExpr.cpp test/Sema/knr-variadic-def.c

Neil Booth neil at daikokuya.co.uk
Mon Jun 1 04:26:22 PDT 2009


Eli Friedman wrote:-

> PR4287: allow a variadic prototype to make a subsequent K&R style 
> definition variadic.  I'm not completely sure it's legal, but the 
> standard can be interpreted as making it legal, and gcc seems to think 
> it's legal, so I didn't add an extension warning.
> 
> +char *foo = "test";
> +int test(char*,...);
> +
> +int test(fmt)
> +        char*fmt;
> +{
> +        va_list ap;
> +        char*a;
> +        int x;
> +
> +        va_start(ap,fmt);
> +        a=va_arg(ap,char*);
> +        x=(a!=foo);
> +        va_end(ap);
> +        return x;
> +}
> +
> +void exit();
> +
> +int main(argc,argv)
> +        int argc;char**argv;
> +{
> +        exit(test("",foo));
> +}
> +

EDG and my FE reject your example, though I agree the standard's
wording isn't entirely clear.  It boils down to whether you can
claim they agree in the number of parameters, which I find a bit
of a stretch.  In any case the case of test with the extra
argument is definitely undefined behaviour.

Neil.



More information about the cfe-commits mailing list