Question about FunctionDecl::isVariadic()

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 2 12:16:17 PDT 2015


Given the following two function declarations:

void f1(...);
void f2();

It makes sense to me that isVariadic() returns true for f1 in both C
and C++. It makes sense to me that isVariadic() returns false for f2
in C++. I am confused as to why it returns false instead of true for
C, however.

In C11, 6.7.6.3p9 states: If the list terminates with an ellipsis (,
...), no information about the number or types of the parameters after
the comma is supplied.

p14 states, in part: "The empty list in a function declarator that is
not part of a definition of that function specifies that no
information about the number or types of the parameters is supplied."

It seems to me that for function *declarations* (not definitions),
isVariadic() should return true for f2 in C. Is there a reason it
doesn't currently behave that way, or is this a bug?

I ask because I was writing an AST matcher for isVariadic() for an
in-progress checker, but the checker was failing to catch that f2 was
a variadic function. I am not certain whether
FunctionDecl::isVariadic() should be changed, whether the AST matcher
isVariadic() should be smarter about C code, or whether the checker
itself needs to be smarter about this particular behavior in C code.
My gut reaction is that FunctionDecl::isVariadic() has a bug, but from
looking at code elsewhere, everything seems to assume isVariadic()
implies the ellipsis, which makes me think I just need to make my
checker smarter.

Thanks!

~Aaron


More information about the cfe-commits mailing list