[cfe-commits] r79911 - in /cfe/trunk: lib/Parse/ParseCXXInlineMethods.cpp lib/Sema/SemaDeclCXX.cpp test/SemaTemplate/constructor-template.cpp

Douglas Gregor dgregor at apple.com
Mon Aug 24 04:57:43 PDT 2009


Author: dgregor
Date: Mon Aug 24 06:57:43 2009
New Revision: 79911

URL: http://llvm.org/viewvc/llvm-project?rev=79911&view=rev
Log:
Make sure to adjust function template declarations to their templated
declarations (e.g., FunctionTemplateDecl -> CXXConstructorDecl) before
performing semantic analysis on the declarations. Fixes PR4761.

Modified:
    cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaTemplate/constructor-template.cpp

Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=79911&r1=79910&r2=79911&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Mon Aug 24 06:57:43 2009
@@ -174,7 +174,7 @@
     // Append the current token at the end of the new token stream so that it
     // doesn't get lost.
     LM.Toks.push_back(Tok);
-    PP.EnterTokenStream(&LM.Toks.front(), LM.Toks.size(), true, false);
+    PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false);
 
     // Consume the previously pushed token.
     ConsumeAnyToken();

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Aug 24 06:57:43 2009
@@ -703,6 +703,8 @@
   if (!ConstructorD)
     return true;
   
+  AdjustDeclIfTemplate(ConstructorD);
+  
   CXXConstructorDecl *Constructor 
     = dyn_cast<CXXConstructorDecl>(ConstructorD.getAs<Decl>());
   if (!Constructor) {
@@ -922,6 +924,8 @@
                                 MemInitTy **MemInits, unsigned NumMemInits) {
   if (!ConstructorDecl)
     return;
+
+  AdjustDeclIfTemplate(ConstructorDecl);
   
   CXXConstructorDecl *Constructor 
     = dyn_cast<CXXConstructorDecl>(ConstructorDecl.getAs<Decl>());
@@ -1041,6 +1045,8 @@
   if (!CDtorDecl)
     return;
   
+  AdjustDeclIfTemplate(CDtorDecl);
+  
   if (CXXConstructorDecl *Constructor 
       = dyn_cast<CXXConstructorDecl>(CDtorDecl.getAs<Decl>()))
     BuildBaseOrMemberInitializers(Context,
@@ -1529,6 +1535,8 @@
   if (!MethodD)
     return;
   
+  AdjustDeclIfTemplate(MethodD);
+  
   CXXScopeSpec SS;
   FunctionDecl *Method = cast<FunctionDecl>(MethodD.getAs<Decl>());
   QualType ClassTy 
@@ -1569,6 +1577,8 @@
   if (!MethodD)
     return;
   
+  AdjustDeclIfTemplate(MethodD);
+  
   FunctionDecl *Method = cast<FunctionDecl>(MethodD.getAs<Decl>());
   CXXScopeSpec SS;
   QualType ClassTy 
@@ -3648,6 +3658,8 @@
 }
 
 void Sema::SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc) {
+  AdjustDeclIfTemplate(dcl);
+  
   Decl *Dcl = dcl.getAs<Decl>();
   FunctionDecl *Fn = dyn_cast<FunctionDecl>(Dcl);
   if (!Fn) {
@@ -3782,6 +3794,8 @@
 /// static data member of class X, names should be looked up in the scope of
 /// class X.
 void Sema::ActOnCXXEnterDeclInitializer(Scope *S, DeclPtrTy Dcl) {
+  AdjustDeclIfTemplate(Dcl);
+  
   Decl *D = Dcl.getAs<Decl>();
   // If there is no declaration, there was an error parsing it.
   if (D == 0)
@@ -3805,6 +3819,8 @@
 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
 /// initializer for the declaration 'Dcl'.
 void Sema::ActOnCXXExitDeclInitializer(Scope *S, DeclPtrTy Dcl) {
+  AdjustDeclIfTemplate(Dcl);
+  
   Decl *D = Dcl.getAs<Decl>();
   // If there is no declaration, there was an error parsing it.
   if (D == 0)

Modified: cfe/trunk/test/SemaTemplate/constructor-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/constructor-template.cpp?rev=79911&r1=79910&r2=79911&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/constructor-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/constructor-template.cpp Mon Aug 24 06:57:43 2009
@@ -4,6 +4,10 @@
   X0(int); // expected-note{{candidate}}
   template<typename T> X0(T);
   template<typename T, typename U> X0(T*, U*);
+  
+  // PR4761
+  template<typename T> X0() : f0(T::foo) {}
+  int f0;
 };
 
 void accept_X0(X0);





More information about the cfe-commits mailing list