aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-06-11 16:06:49 +0000
committerAnders Carlsson <andersca@mac.com>2009-06-11 16:06:49 +0000
commit3b56c002591b59c6c257951f6613b44de83fa860 (patch)
tree21a6ed624af8f7f8db6285d08d8ce50593e09392
parent01cd4fb8259c5339279dea5eb5b40b02f1fa8d0f (diff)
Add a null check that fixes the crash in PR4362, and make sure to instantiate non-type template arguments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73193 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaTemplate.cpp20
-rw-r--r--test/SemaTemplate/default-arguments.cpp9
2 files changed, 26 insertions, 3 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index f9176ca470..f03c1acb8e 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -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;
}
diff --git a/test/SemaTemplate/default-arguments.cpp b/test/SemaTemplate/default-arguments.cpp
index 5b6ab7d155..f9bb44ecb9 100644
--- a/test/SemaTemplate/default-arguments.cpp
+++ b/test/SemaTemplate/default-arguments.cpp
@@ -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>;