diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-02-18 07:07:28 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-02-18 07:07:28 +0000 |
commit | 965acbb321e94e36aa5365126eee46b97745fdbb (patch) | |
tree | b90c16f0aedbfca9146e07251c896cd22d9fd9c6 /lib/Sema/SemaType.cpp | |
parent | c6c16af963eddc3e9b75b5d2614d069e1162fe27 (diff) |
Allow "overloadable" functions in C to be declared as variadic without
any named parameters, e.g., this is accepted in C:
void f(...) __attribute__((overloadable));
although this would be rejected:
void f(...);
To do this, moved the checking of the "ellipsis without any named
arguments" condition from the parser into Sema (where it belongs anyway).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64902 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaType.cpp')
-rw-r--r-- | lib/Sema/SemaType.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index e6aafdab08..a385a13f4c 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -474,6 +474,22 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip) { // C++ 8.3.5p2: If the parameter-declaration-clause is empty, the // function takes no arguments. T = Context.getFunctionType(T, NULL, 0, FTI.isVariadic,FTI.TypeQuals); + } else if (FTI.isVariadic) { + // We allow a zero-parameter variadic function in C if the + // function is marked with the "overloadable" + // attribute. Scan for this attribute now. + bool Overloadable = false; + for (const AttributeList *Attrs = D.getAttributes(); + Attrs; Attrs = Attrs->getNext()) { + if (Attrs->getKind() == AttributeList::AT_overloadable) { + Overloadable = true; + break; + } + } + + if (!Overloadable) + Diag(FTI.getEllipsisLoc(), diag::err_ellipsis_first_arg); + T = Context.getFunctionType(T, NULL, 0, FTI.isVariadic, 0); } else { // Simple void foo(), where the incoming T is the result type. T = Context.getFunctionTypeNoProto(T); |