aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2010-12-10 17:08:53 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2010-12-10 17:08:53 +0000
commit9f6f6a107287bd81aedab8b578216535b0b51d0f (patch)
tree9a92d8cab97dc276b8d09f5b19db827a1fd84826
parent9913d6e086b95cdc791b52c10f773dfd1267f5f8 (diff)
Do not substitute template types if template has dependent context
We should not substitute template types if the template has a dependent context because the template argument stack is not yet fully formed. Instead, defer substitution until the template has a non-dependent context (i.e. instantiation of an outer template). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121491 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaTemplate.cpp7
-rw-r--r--test/SemaTemplate/instantiate-template-template-parm.cpp15
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 7539a56965..53a02a9886 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -2110,9 +2110,12 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param,
// Check non-type template parameters.
if (NonTypeTemplateParmDecl *NTTP =dyn_cast<NonTypeTemplateParmDecl>(Param)) {
// Do substitution on the type of the non-type template parameter
- // with the template arguments we've seen thus far.
+ // with the template arguments we've seen thus far. But if the
+ // template has a dependent context then we cannot substitute yet.
QualType NTTPType = NTTP->getType();
- if (NTTPType->isDependentType()) {
+ if (NTTPType->isDependentType() &&
+ !isa<TemplateTemplateParmDecl>(Template) &&
+ !Template->getDeclContext()->isDependentContext()) {
// Do substitution on the type of the non-type template parameter.
InstantiatingTemplate Inst(*this, TemplateLoc, Template,
NTTP, Converted.data(), Converted.size(),
diff --git a/test/SemaTemplate/instantiate-template-template-parm.cpp b/test/SemaTemplate/instantiate-template-template-parm.cpp
index f48a0c7a71..1e3346998f 100644
--- a/test/SemaTemplate/instantiate-template-template-parm.cpp
+++ b/test/SemaTemplate/instantiate-template-template-parm.cpp
@@ -44,3 +44,18 @@ template<long V> struct X3l { }; // expected-note{{different type 'long'}}
X2<int, X3i> x2okay;
X2<long, X3l> x2bad; // expected-note{{instantiation}}
+
+template <typename T, template <T, T> class TT, class R = TT<1, 2> >
+struct Comp {
+ typedef R r1;
+ template <T x, T y> struct gt {
+ static const bool result = x > y;
+ };
+ typedef gt<2, 1> r2;
+};
+
+template <int x, int y> struct lt {
+ static const bool result = x < y;
+};
+
+Comp<int, lt> c0;