[cfe-commits] r89050 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-using-decl.cpp

Douglas Gregor dgregor at apple.com
Mon Nov 16 22:07:40 PST 2009


Author: dgregor
Date: Tue Nov 17 00:07:40 2009
New Revision: 89050

URL: http://llvm.org/viewvc/llvm-project?rev=89050&view=rev
Log:
Implement template instantiation for using directives, which is dead simple.

Also, make the "don't know how to instantiate a particular kind of
declaration" diagnostic nicer, so we don't have to trap Clang in a
debugger to figure out what went wrong.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-using-decl.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=89050&r1=89049&r2=89050&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Nov 17 00:07:40 2009
@@ -65,11 +65,17 @@
     Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
     Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
     Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
+    Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
     Decl *VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D);
 
     // Base case. FIXME: Remove once we can instantiate everything.
-    Decl *VisitDecl(Decl *) {
-      assert(false && "Template instantiation of unknown declaration kind!");
+    Decl *VisitDecl(Decl *D) {
+      unsigned DiagID = SemaRef.getDiagnostics().getCustomDiagID(
+                                                            Diagnostic::Error,
+                                                   "cannot instantiate %0 yet");
+      SemaRef.Diag(D->getLocation(), DiagID)
+        << D->getDeclKindName();
+      
       return 0;
     }
 
@@ -1005,6 +1011,20 @@
   return Param;
 }
 
+Decl *TemplateDeclInstantiator::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
+  // Using directives are never dependent, so they require no explicit
+  
+  UsingDirectiveDecl *Inst
+    = UsingDirectiveDecl::Create(SemaRef.Context, Owner, D->getLocation(),
+                                 D->getNamespaceKeyLocation(), 
+                                 D->getQualifierRange(), D->getQualifier(), 
+                                 D->getIdentLocation(), 
+                                 D->getNominatedNamespace(), 
+                                 D->getCommonAncestor());
+  Owner->addDecl(Inst);
+  return Inst;
+}
+
 Decl *
 TemplateDeclInstantiator::VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D) {
   NestedNameSpecifier *NNS =

Modified: cfe/trunk/test/SemaTemplate/instantiate-using-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-using-decl.cpp?rev=89050&r1=89049&r2=89050&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-using-decl.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-using-decl.cpp Tue Nov 17 00:07:40 2009
@@ -1,5 +1,7 @@
 // RUN: clang-cc -fsyntax-only -verify %s
 
+namespace N { }
+
 template<typename T>
 struct A {
   void f();
@@ -10,6 +12,7 @@
   using A<T>::f;
   
   void g() {
+    using namespace N;
     f();
   }
 };





More information about the cfe-commits mailing list