]> granicus.if.org Git - clang/commitdiff
When declaring a function template, create a FunctionTemplateDecl node
authorDouglas Gregor <dgregor@apple.com>
Wed, 24 Jun 2009 00:23:40 +0000 (00:23 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 24 Jun 2009 00:23:40 +0000 (00:23 +0000)
and associate it with the FunctionDecl.

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

lib/Sema/SemaDecl.cpp
lib/Sema/SemaTemplate.cpp

index 10ab5c2d3978ca072fe1574b120aa516a20510f6..48d1d64de14b13f6abfb11e90d48a937ad6f973e 100644 (file)
@@ -2157,6 +2157,26 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
   // from the semantic context.
   NewFD->setLexicalDeclContext(CurContext);
 
+  // If there is a template parameter list, then we are dealing with a 
+  // template declaration or specialization.
+  FunctionTemplateDecl *FunctionTemplate = 0;
+  if (TemplateParamLists.size()) {
+    // FIXME: member templates!
+    TemplateParameterList *TemplateParams 
+      = static_cast<TemplateParameterList *>(*TemplateParamLists.release());
+    
+    if (TemplateParams->size() > 0) {
+      // This is a function template
+      FunctionTemplate = FunctionTemplateDecl::Create(Context, CurContext,
+                                                      NewFD->getLocation(),
+                                                      Name, TemplateParams,
+                                                      NewFD);
+      NewFD->setDescribedFunctionTemplate(FunctionTemplate);
+    } else {
+      // FIXME: Handle function template specializations
+    }
+  }
+  
   // C++ [dcl.fct.spec]p5:
   //   The virtual specifier shall only be used in declarations of
   //   nonstatic class member functions that appear within a
index 26e56733a13ec08ac4cd85dbaf0c9a2e5da079fd..4ecb44c3c5f31428e22371b250ec8c60eaa35213 100644 (file)
@@ -67,9 +67,10 @@ TemplateNameKind Sema::isTemplateName(const IdentifierInfo &II, Scope *S,
       }
     }
 
-    // FIXME: What follows is a gross hack.
+    // FIXME: What follows is a slightly less gross hack than what used to 
+    // follow.
     if (FunctionDecl *FD = dyn_cast<FunctionDecl>(IIDecl)) {
-      if (FD->getType()->isDependentType()) {
+      if (FD->getDescribedFunctionTemplate()) {
         TemplateResult = TemplateTy::make(FD);
         return TNK_Function_template;
       }
@@ -78,7 +79,7 @@ TemplateNameKind Sema::isTemplateName(const IdentifierInfo &II, Scope *S,
       for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(),
                                                   FEnd = Ovl->function_end();
            F != FEnd; ++F) {
-        if ((*F)->getType()->isDependentType()) {
+        if ((*F)->getDescribedFunctionTemplate()) {
           TemplateResult = TemplateTy::make(Ovl);
           return TNK_Function_template;
         }