aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-01-06 22:09:01 +0000
committerDouglas Gregor <dgregor@apple.com>2011-01-06 22:09:01 +0000
commitf5c65ffbd7374b6c8d9f1e361041578640cab320 (patch)
tree8d66e21f4816c23a70b7b26a28eec54caafb66c3 /lib/AST/Decl.cpp
parent150d2df7b659105cfbab39cc85af225391952815 (diff)
Implement template argument deduction from a call to a function
template whose last parameter is a parameter pack. This allows us to form a call to, e.g., template<typename ...Args1, typename ...Args2> void f(std::pair<Args1, Args2> ...pairs); given zero or more instances of "pair". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122973 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r--lib/AST/Decl.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index c51d2cdc37..a76a5748b4 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -1442,11 +1442,20 @@ void FunctionDecl::setParams(ASTContext &C,
/// 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++).
+/// arguments (in C++) or the last parameter is a parameter pack.
unsigned FunctionDecl::getMinRequiredArguments() const {
- unsigned NumRequiredArgs = getNumParams();
- while (NumRequiredArgs > 0
- && getParamDecl(NumRequiredArgs-1)->hasDefaultArg())
+ 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;
return NumRequiredArgs;