]> granicus.if.org Git - clang/commitdiff
When declaring a class template whose name is qualified, make sure
authorDouglas Gregor <dgregor@apple.com>
Mon, 12 Oct 2009 23:11:44 +0000 (23:11 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 12 Oct 2009 23:11:44 +0000 (23:11 +0000)
that the scope in which it is being declared is complete. Also, when
instantiating a member class template's ClassTemplateDecl, be sure to
delay type creation so that the resulting type is dependent. Ick.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83923 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/CXX/temp/temp.spec/temp.expl.spec/p18.cpp [new file with mode: 0644]

index 8ca9089c5e34f9fe3139f00ed7680a7b4a19f754..9d39ddbe68f40efb5bd1efe519d4041f55265581 100644 (file)
@@ -574,6 +574,9 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
   DeclContext *SemanticContext;
   LookupResult Previous;
   if (SS.isNotEmpty() && !SS.isInvalid()) {
+    if (RequireCompleteDeclContext(SS))
+      return true;
+
     SemanticContext = computeDeclContext(SS, true);
     if (!SemanticContext) {
       // FIXME: Produce a reasonable diagnostic here
index 916e44329471b96981fe5cbde19eaa884006dd7a..4fd2a734b1f022eeaf08063695f98fa3e0d44466 100644 (file)
@@ -390,7 +390,8 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   CXXRecordDecl *RecordInst
     = CXXRecordDecl::Create(SemaRef.Context, Pattern->getTagKind(), Owner,
                             Pattern->getLocation(), Pattern->getIdentifier(),
-                            Pattern->getTagKeywordLoc(), /*PrevDecl=*/ NULL);
+                            Pattern->getTagKeywordLoc(), /*PrevDecl=*/ NULL,
+                            /*DelayTypeCreation=*/true);
 
   ClassTemplateDecl *Inst
     = ClassTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(),
@@ -398,7 +399,10 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   RecordInst->setDescribedClassTemplate(Inst);
   Inst->setAccess(D->getAccess());
   Inst->setInstantiatedFromMemberTemplate(D);
-
+  
+  // Trigger creation of the type for the instantiation.
+  SemaRef.Context.getTypeDeclType(RecordInst);
+  
   Owner->addDecl(Inst);
   return Inst;
 }
diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/p18.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/p18.cpp
new file mode 100644 (file)
index 0000000..112444a
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+template<class T1> class A { 
+  template<class T2> class B {
+    template<class T3> void mf1(T3); 
+    void mf2();
+  };
+}; 
+
+template<> template<class X>
+class A<int>::B { }; 
+
+template<> template<> template<class T>
+  void A<int>::B<double>::mf1(T t) { } 
+
+template<class Y> template<>
+  void A<Y>::B<double>::mf2() { } // expected-error{{does not refer}}