[cfe-commits] r102914 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-method.cpp

Douglas Gregor dgregor at apple.com
Mon May 3 08:32:18 PDT 2010


Author: dgregor
Date: Mon May  3 10:32:18 2010
New Revision: 102914

URL: http://llvm.org/viewvc/llvm-project?rev=102914&view=rev
Log:
When instantiating a member function declared via a typedef, don't try
to enter the instantiated parameter declarations into the local
instantiation scope; they can't be referenced anyway. Fixes PR7022.

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

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=102914&r1=102913&r2=102914&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon May  3 10:32:18 2010
@@ -1776,28 +1776,32 @@
   if (NewTInfo != OldTInfo) {
     // Get parameters from the new type info.
     TypeLoc OldTL = OldTInfo->getTypeLoc();
-    FunctionProtoTypeLoc *OldProtoLoc = cast<FunctionProtoTypeLoc>(&OldTL);
-    TypeLoc NewTL = NewTInfo->getTypeLoc();
-    FunctionProtoTypeLoc *NewProtoLoc = cast<FunctionProtoTypeLoc>(&NewTL);
-    assert(NewProtoLoc && "Missing prototype?");
-    for (unsigned i = 0, i_end = NewProtoLoc->getNumArgs(); i != i_end; ++i) {
-      // FIXME: Variadic templates will break this.
-      Params.push_back(NewProtoLoc->getArg(i));
-      SemaRef.CurrentInstantiationScope->InstantiatedLocal(
+    if (FunctionProtoTypeLoc *OldProtoLoc
+                                  = dyn_cast<FunctionProtoTypeLoc>(&OldTL)) {
+      TypeLoc NewTL = NewTInfo->getTypeLoc();
+      FunctionProtoTypeLoc *NewProtoLoc = cast<FunctionProtoTypeLoc>(&NewTL);
+      assert(NewProtoLoc && "Missing prototype?");
+      for (unsigned i = 0, i_end = NewProtoLoc->getNumArgs(); i != i_end; ++i) {
+        // FIXME: Variadic templates will break this.
+        Params.push_back(NewProtoLoc->getArg(i));
+        SemaRef.CurrentInstantiationScope->InstantiatedLocal(
                                                         OldProtoLoc->getArg(i),
                                                         NewProtoLoc->getArg(i));
+      }
     }
   } else {
     // The function type itself was not dependent and therefore no
     // substitution occurred. However, we still need to instantiate
     // the function parameters themselves.
     TypeLoc OldTL = OldTInfo->getTypeLoc();
-    FunctionProtoTypeLoc *OldProtoLoc = cast<FunctionProtoTypeLoc>(&OldTL);
-    for (unsigned i = 0, i_end = OldProtoLoc->getNumArgs(); i != i_end; ++i) {
-      ParmVarDecl *Parm = VisitParmVarDecl(OldProtoLoc->getArg(i));
-      if (!Parm)
-        return 0;
-      Params.push_back(Parm);
+    if (FunctionProtoTypeLoc *OldProtoLoc
+                                    = dyn_cast<FunctionProtoTypeLoc>(&OldTL)) {
+      for (unsigned i = 0, i_end = OldProtoLoc->getNumArgs(); i != i_end; ++i) {
+        ParmVarDecl *Parm = VisitParmVarDecl(OldProtoLoc->getArg(i));
+        if (!Parm)
+          return 0;
+        Params.push_back(Parm);
+      }
     }
   }
   return NewTInfo;

Modified: cfe/trunk/test/SemaTemplate/instantiate-method.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-method.cpp?rev=102914&r1=102913&r2=102914&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-method.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-method.cpp Mon May  3 10:32:18 2010
@@ -152,3 +152,26 @@
   }
 
 }
+
+namespace PR7022 {
+  template <typename > 
+  struct X1
+  {
+    typedef int state_t( );
+    state_t g ;
+  };
+
+  template <  typename U = X1<int> > struct X2
+  {
+    X2( U = U())
+    {
+    }
+  };
+
+  void m(void)
+  {
+    typedef X2<> X2_type;
+    X2_type c;
+  }
+
+}





More information about the cfe-commits mailing list