[cfe-commits] r132529 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp test/CXX/temp/temp.param/p9-0x.cpp
Douglas Gregor
dgregor at apple.com
Thu Jun 2 19:59:40 PDT 2011
Author: dgregor
Date: Thu Jun 2 21:59:40 2011
New Revision: 132529
URL: http://llvm.org/viewvc/llvm-project?rev=132529&view=rev
Log:
When checking the instantiation of a default template argument against
the template parameter, perform the checking as a "specified" template
argument rather than a "deduced" template argument; the latter implies
stricter type checking that is not permitted for default template
arguments.
Also, cleanup our handling of substitution of explicit template
arguments for a function template. We were actually performing some
substitution of default arguments at this point!
Fixes PR10069.
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/CXX/temp/temp.param/p9-0x.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=132529&r1=132528&r2=132529&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Jun 2 21:59:40 2011
@@ -2819,9 +2819,6 @@
unsigned ArgIdx = 0;
LocalInstantiationScope InstScope(*this, true);
while (Param != ParamEnd) {
- if (ArgIdx > NumArgs && PartialTemplateArgs)
- break;
-
if (ArgIdx < NumArgs) {
// If we have an expanded parameter pack, make sure we don't have too
// many arguments.
@@ -2862,6 +2859,16 @@
continue;
}
+ // If we're checking a partial template argument list, we're done.
+ if (PartialTemplateArgs) {
+ if ((*Param)->isTemplateParameterPack() && !ArgumentPack.empty())
+ Converted.push_back(TemplateArgument::CreatePackCopy(Context,
+ ArgumentPack.data(),
+ ArgumentPack.size()));
+
+ return Invalid;
+ }
+
// If we have a template parameter pack with no more corresponding
// arguments, just break out now and we'll fill in the argument pack below.
if ((*Param)->isTemplateParameterPack())
@@ -2887,7 +2894,7 @@
// the default argument.
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
if (!TTP->hasDefaultArgument()) {
- assert((Invalid || PartialTemplateArgs) && "Missing default argument");
+ assert(Invalid && "Missing default argument");
break;
}
@@ -2905,7 +2912,7 @@
} else if (NonTypeTemplateParmDecl *NTTP
= dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
if (!NTTP->hasDefaultArgument()) {
- assert((Invalid || PartialTemplateArgs) && "Missing default argument");
+ assert(Invalid && "Missing default argument");
break;
}
@@ -2924,7 +2931,7 @@
= cast<TemplateTemplateParmDecl>(*Param);
if (!TempParm->hasDefaultArgument()) {
- assert((Invalid || PartialTemplateArgs) && "Missing default argument");
+ assert(Invalid && "Missing default argument");
break;
}
@@ -2970,9 +2977,7 @@
// in arguments for non-template parameter packs.
if ((*Param)->isTemplateParameterPack()) {
- if (PartialTemplateArgs && ArgumentPack.empty()) {
- Converted.push_back(TemplateArgument());
- } else if (ArgumentPack.empty())
+ if (ArgumentPack.empty())
Converted.push_back(TemplateArgument(0, 0));
else {
Converted.push_back(TemplateArgument::CreatePackCopy(Context,
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=132529&r1=132528&r2=132529&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Thu Jun 2 21:59:40 2011
@@ -2314,7 +2314,7 @@
FunctionTemplate->getLocation(),
FunctionTemplate->getSourceRange().getEnd(),
0, Builder,
- CTAK_Deduced)) {
+ CTAK_Specified)) {
Info.Param = makeTemplateParameter(
const_cast<NamedDecl *>(TemplateParams->getParam(I)));
// FIXME: These template arguments are temporary. Free them!
Modified: cfe/trunk/test/CXX/temp/temp.param/p9-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.param/p9-0x.cpp?rev=132529&r1=132528&r2=132529&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.param/p9-0x.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.param/p9-0x.cpp Thu Jun 2 21:59:40 2011
@@ -50,3 +50,12 @@
template<typename T = int> struct Inner::X3 { };
template<typename T = int> void Inner::f2() {}
}
+
+namespace PR10069 {
+ template<typename T, T a, T b=0, T c=1>
+ T f(T x);
+
+ void g() {
+ f<unsigned int, 0>(0);
+ }
+}
More information about the cfe-commits
mailing list