diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-04-01 19:18:16 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-04-01 19:18:16 +0000 |
commit | 911517848ddd763de8c05da87849eb0315f826e3 (patch) | |
tree | 18662f3f17c14ba373b0c79bc0e7305f0f378111 /clang/lib/AST/Decl.cpp | |
parent | 068fc01234b1a393c28d1860cf9d0981d9fc4644 (diff) | |
download | bcm5719-llvm-911517848ddd763de8c05da87849eb0315f826e3.tar.gz bcm5719-llvm-911517848ddd763de8c05da87849eb0315f826e3.zip |
Simplify FunctionDecl::getMinRequiredArguments().
llvm-svn: 205351
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 050e61c1f87..c2e1a848c13 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2534,35 +2534,15 @@ void FunctionDecl::setDeclsInPrototypeScope(ArrayRef<NamedDecl *> NewDecls) { /// getMinRequiredArguments - Returns the minimum number of arguments /// needed to call this function. This may be fewer than the number of /// function parameters, if some of the parameters have default -/// arguments (in C++) or the last parameter is a parameter pack. +/// arguments (in C++) or are parameter packs (C++11). unsigned FunctionDecl::getMinRequiredArguments() const { if (!getASTContext().getLangOpts().CPlusPlus) return getNumParams(); - - unsigned NumRequiredArgs = getNumParams(); - - // If the last parameter is a parameter pack, we don't need an argument for - // it. - if (NumRequiredArgs > 0 && - getParamDecl(NumRequiredArgs - 1)->isParameterPack()) - --NumRequiredArgs; - - // If this parameter has a default argument, we don't need an argument for - // it. - while (NumRequiredArgs > 0 && - getParamDecl(NumRequiredArgs-1)->hasDefaultArg()) - --NumRequiredArgs; - - // We might have parameter packs before the end. These can't be deduced, - // but they can still handle multiple arguments. - unsigned ArgIdx = NumRequiredArgs; - while (ArgIdx > 0) { - if (getParamDecl(ArgIdx - 1)->isParameterPack()) - NumRequiredArgs = ArgIdx; - - --ArgIdx; - } - + + unsigned NumRequiredArgs = 0; + for (auto *Param : params()) + if (!Param->isParameterPack() && !Param->hasDefaultArg()) + ++NumRequiredArgs; return NumRequiredArgs; } |