]> granicus.if.org Git - clang/commitdiff
Make sure that the template parameter lists get from the parser down to ActOnFunction...
authorDouglas Gregor <dgregor@apple.com>
Wed, 24 Jun 2009 00:54:41 +0000 (00:54 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 24 Jun 2009 00:54:41 +0000 (00:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74040 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Action.h
include/clang/Parse/Parser.h
lib/Parse/ParseTemplate.cpp
lib/Parse/Parser.cpp
lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaTemplate.cpp
test/Parser/cxx-template-decl.cpp

index 933a13803f53ef5003c79ee39492689e74804557..fa3160468e3092db2c098539ee690e5e91fa8def 100644 (file)
@@ -1465,6 +1465,14 @@ public:
     return DeclPtrTy();
   }
   
+  /// \brief Invoked when the parser is beginning to parse a function template
+  /// or function template specialization definition.
+  virtual DeclPtrTy ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 
+                                MultiTemplateParamsArg TemplateParameterLists,
+                                                    Declarator &D) {
+    return DeclPtrTy();
+  }
+  
   /// \brief Process the explicit instantiation of a class template
   /// specialization.
   ///
index f6da6120574ed029022571b6ed92d60f7f198eab..890820123444fbcf1c84a5cf60b4926db4afdd1e 100644 (file)
@@ -636,7 +636,8 @@ private:
   DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(
             AccessSpecifier AS = AS_none);
                                                
-  DeclPtrTy ParseFunctionDefinition(Declarator &D);
+  DeclPtrTy ParseFunctionDefinition(Declarator &D,
+                 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
   void ParseKNRParamDeclarations(Declarator &D);
   // EndLoc, if non-NULL, is filled with the location of the last token of
   // the simple-asm.
index daf9500af88d0dfedf2682ad3c2bf2d87d28f2fa..ab359f4c5e062031414573e64401615bfa8c1f2c 100644 (file)
@@ -201,7 +201,7 @@ Parser::ParseSingleDeclarationAfterTemplate(
       }
       return DeclPtrTy();
     }
-    return ParseFunctionDefinition(DeclaratorInfo);
+    return ParseFunctionDefinition(DeclaratorInfo, TemplateInfo);
   }
 
   if (DeclaratorInfo.isFunctionDeclarator())
index a2a66f9255ded2b6822ee50171d5876f2ff6a09d..18048443223035f8c4d39a51b63afa6f1b40617f 100644 (file)
@@ -590,7 +590,8 @@ Parser::ParseDeclarationOrFunctionDefinition(AccessSpecifier AS) {
 /// [C++] function-definition: [C++ 8.4]
 ///         decl-specifier-seq[opt] declarator function-try-block
 ///
-Parser::DeclPtrTy Parser::ParseFunctionDefinition(Declarator &D) {
+Parser::DeclPtrTy Parser::ParseFunctionDefinition(Declarator &D,
+                                     const ParsedTemplateInfo &TemplateInfo) {
   const DeclaratorChunk &FnTypeInfo = D.getTypeObject(0);
   assert(FnTypeInfo.Kind == DeclaratorChunk::Function &&
          "This isn't a function declarator!");
@@ -632,7 +633,13 @@ Parser::DeclPtrTy Parser::ParseFunctionDefinition(Declarator &D) {
 
   // Tell the actions module that we have entered a function definition with the
   // specified Declarator for the function.
-  DeclPtrTy Res = Actions.ActOnStartOfFunctionDef(CurScope, D);
+  DeclPtrTy Res = TemplateInfo.TemplateParams? 
+      Actions.ActOnStartOfFunctionTemplateDef(CurScope,
+                              Action::MultiTemplateParamsArg(Actions,
+                                          TemplateInfo.TemplateParams->data(),
+                                         TemplateInfo.TemplateParams->size()),
+                                              D)
+    : Actions.ActOnStartOfFunctionDef(CurScope, D);
 
   if (Tok.is(tok::kw_try))
     return ParseFunctionTryBlock(Res);
index 23e12d80c98918e2a754bbfbfb028a96f0a14e2d..699316efef675e71b9550b25f13edccee2f411ab 100644 (file)
@@ -2077,6 +2077,10 @@ public:
                                   MultiTemplateParamsArg TemplateParameterLists,
                                             Declarator &D);
   
+  virtual DeclPtrTy ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 
+                                                    MultiTemplateParamsArg TemplateParameterLists,
+                                                    Declarator &D);
+  
   virtual DeclResult
   ActOnExplicitInstantiation(Scope *S, SourceLocation TemplateLoc,
                              unsigned TagSpec, 
index 7c4cb60fd585bd974f3a8a1611612fb62fa243a8..c319f7f9698d74b9877113717bf9e206800b4a6b 100644 (file)
@@ -3037,6 +3037,8 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope,
 }
 
 Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) {
+  if (!D)
+    return D;
   FunctionDecl *FD = cast<FunctionDecl>(D.getAs<Decl>());
 
   CurFunctionNeedsScopeChecking = false;
index 4ecb44c3c5f31428e22371b250ec8c60eaa35213..63696a13d3e0b5dd9bc128b6cef7f3e81a1241dd 100644 (file)
@@ -2507,6 +2507,27 @@ Sema::ActOnTemplateDeclarator(Scope *S,
   return HandleDeclarator(S, D, move(TemplateParameterLists), false);
 }
 
+Sema::DeclPtrTy 
+Sema::ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 
+                               MultiTemplateParamsArg TemplateParameterLists,
+                                      Declarator &D) {
+  assert(getCurFunctionDecl() == 0 && "Function parsing confused");
+  assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function &&
+         "Not a function declarator!");
+  DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun;
+  
+  if (FTI.hasPrototype) {
+    // FIXME: Diagnose arguments without names in C. 
+  }
+  
+  Scope *ParentScope = FnBodyScope->getParent();
+  
+  DeclPtrTy DP = HandleDeclarator(ParentScope, D, 
+                                  move(TemplateParameterLists),
+                                  /*IsFunctionDefinition=*/true);
+  return ActOnStartOfFunctionDef(FnBodyScope, DP);  
+}
+
 // Explicit instantiation of a class template specialization
 Sema::DeclResult
 Sema::ActOnExplicitInstantiation(Scope *S, SourceLocation TemplateLoc,
index 75b26a98e44ec8a2588e7544c826c5f3b6ac9d51..aaf3ee77a3694dfdeda29c7782c38a7cffd2e701 100644 (file)
@@ -37,7 +37,7 @@ template <template <typename> class T = foo> class TTP3; // FIXME:expected-error
 template <template <typename> class = foo> class TTP3; // FIXME:expected-error{{template argument for template template parameter must be a template}}
 template <template <typename X, typename Y> class T> class TTP5;
 
-// Forward declararations with non-type params
+// Forward declarations with non-type params
 template <int> class NTP0;
 template <int N> class NTP1;
 template <int N = 5> class NTP2;