diff options
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 3713776298..dbc92f414f 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -176,16 +176,26 @@ Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const { return 0; } -unsigned FunctionDecl::getNumParams() const { - const FunctionType *FT = getType()->getAsFunctionType(); +// Helper function for FunctionDecl::getNumParams and FunctionDecl::setParams() +static unsigned getNumTypeParams(QualType T) { + const FunctionType *FT = T->getAsFunctionType(); if (isa<FunctionTypeNoProto>(FT)) return 0; return cast<FunctionTypeProto>(FT)->getNumArgs(); } +unsigned FunctionDecl::getNumParams() const { + // Can happen if a FunctionDecl is declared using typeof(some_other_func) bar; + if (!ParamInfo) + return 0; + + return getNumTypeParams(getType()); +} + void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) { assert(ParamInfo == 0 && "Already has param info!"); - assert(NumParams == getNumParams() && "Parameter count mismatch!"); + assert(NumParams == getNumTypeParams(getType()) && + "Parameter count mismatch!"); // Zero params -> null pointer. if (NumParams) { |