Add a null check that fixes the crash in PR4362, and make sure to instantiate non-type template arguments.

llvm-svn: 73193
This commit is contained in:
Anders Carlsson 2009-06-11 16:06:49 +00:00
parent 873495ad98
commit 40ed344c92
2 changed files with 26 additions and 3 deletions

View File

@ -1024,8 +1024,21 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
if (!NTTP->hasDefaultArgument())
break;
// FIXME: Instantiate default argument
Arg = TemplateArgument(NTTP->getDefaultArgument());
InstantiatingTemplate Inst(*this, TemplateLoc,
Template, Converted.getFlatArgumentList(),
Converted.flatSize(),
SourceRange(TemplateLoc, RAngleLoc));
TemplateArgumentList TemplateArgs(Context, Converted,
/*CopyArgs=*/false,
/*FlattenArgs=*/false);
Sema::OwningExprResult E = InstantiateExpr(NTTP->getDefaultArgument(),
TemplateArgs);
if (E.isInvalid())
return true;
Arg = TemplateArgument(E.takeAs<Expr>());
} else {
TemplateTemplateParmDecl *TempParm
= cast<TemplateTemplateParmDecl>(*Param);
@ -1400,7 +1413,8 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
// FIXME: Add template argument to Converted!
if (InstantiatedParamType->isDependentType() || Arg->isTypeDependent()) {
// FIXME: Produce a cloned, canonical expression?
Converted->push_back(TemplateArgument(Arg));
if (Converted)
Converted->push_back(TemplateArgument(Arg));
return false;
}

View File

@ -13,3 +13,12 @@ X<> *x4;
template<typename T = int> struct Z { };
template struct Z<>;
// PR4362
template<class T> struct a { };
template<> struct a<int> { static const bool v = true; };
template<class T, bool = a<T>::v> struct p { }; // expected-error {{no member named 'v'}}
template struct p<bool>; // expected-note {{in instantiation of default argument for 'p<bool>' required here}}
template struct p<int>;