diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-06-06 16:00:50 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-06-06 16:00:50 +0000 |
commit | 15fd3ff705a5657be800d3402d919eb8d13ec9f0 (patch) | |
tree | 143c9e71a36f6471a56a5bee73225cec49ca6147 | |
parent | a4c4db1f56bea32f1736a77e4d5556d66d399c72 (diff) | |
download | clang-15fd3ff705a5657be800d3402d919eb8d13ec9f0.tar.gz clang-15fd3ff705a5657be800d3402d919eb8d13ec9f0.tar.bz2 clang-15fd3ff705a5657be800d3402d919eb8d13ec9f0.tar.xz |
PR14841: If partial substitution of explicitly-specified template arguments
results in a template having too many arguments, but all the trailing arguments
are packs, that's OK if we have a partial pack substitution: the trailing pack
expansions may end up empty.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210350 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 11 | ||||
-rw-r--r-- | test/SemaTemplate/pack-deduction.cpp | 12 |
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index d893c88110..d6ea3d0e2e 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -3856,6 +3856,17 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, ++ArgIdx; } + // If we're performing a partial argument substitution, allow any trailing + // pack expansions; they might be empty. This can happen even if + // PartialTemplateArgs is false (the list of arguments is complete but + // still dependent). + if (ArgIdx < NumArgs && CurrentInstantiationScope && + CurrentInstantiationScope->getPartiallySubstitutedPack()) { + while (ArgIdx < NumArgs && + TemplateArgs[ArgIdx].getArgument().isPackExpansion()) + Converted.push_back(TemplateArgs[ArgIdx++].getArgument()); + } + // If we have any leftover arguments, then there were too many arguments. // Complain and fail. if (ArgIdx < NumArgs) diff --git a/test/SemaTemplate/pack-deduction.cpp b/test/SemaTemplate/pack-deduction.cpp index 2d0a03f0fc..abb76de693 100644 --- a/test/SemaTemplate/pack-deduction.cpp +++ b/test/SemaTemplate/pack-deduction.cpp @@ -18,3 +18,15 @@ namespace Nested { int b1 = f2(P<X<int, double>, int>(), P<X<int, double>, double>()); int b2 = f2(P<X<int, double>, int>(), P<X<int, double>, double>(), P<X<int, double>, char>()); // expected-error {{no matching}} } + +namespace PR14841 { + template<typename T, typename U> struct A {}; + template<typename ...Ts> void f(A<Ts...>); // expected-note {{substitution failure [with Ts = <char, short, int>]: too many template arg}} + + void g(A<char, short> a) { + f(a); + f<char>(a); + f<char, short>(a); + f<char, short, int>(a); // expected-error {{no matching function}} + } +} |