Topic: Incorrect varargs warning
Author: Hyman Rosen <hymie@prolifics.com>
Date: 1998/01/15 Raw View
The following program generates an incorrect warning from egcs.
#include <stdarg.h>
struct A { virtual ~A() { } };
void f(A a, ...)
{
va_list va;
va_start(va, a);
va_end(va);
}
Compiling with 'gcc -c' gives
In function `void f(struct A ...)':
6: warning: cannot pass objects of type `A' through `...'
There is no such attempt being made. But this sent me searching through
my draft standard, where I found the following in section 18.7:
If the parameter parmN is declared with a function, array, or
reference type, or with a type that is not compatible with the
type that results when passing an argument for which there is
no parameter, the behavior is undefined.
This appears to mean that parmN must itself be of a type that could be
passed as an extra parameter, even though it appears to be a perfectly
ordinary parameter. Is my interpretation correct? If so, why is this
the case? I understand the reason behind disallowing function, array,
or reference types, since this breaks simple versions of varargs that
just take the address of parmN.
This warning is showing up in some legacy C++ code that implemented a
printf-like function using a C++ string type for the format parameter.
It is not necessary to inform me of the variety of ways that I have to
not use such methods :-)
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]