]> granicus.if.org Git - clang/commitdiff
When instantiating a member function declared via a typedef, don't try
authorDouglas Gregor <dgregor@apple.com>
Mon, 3 May 2010 15:32:18 +0000 (15:32 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 3 May 2010 15:32:18 +0000 (15:32 +0000)
to enter the instantiated parameter declarations into the local
instantiation scope; they can't be referenced anyway. Fixes PR7022.

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

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-method.cpp

index 48b517ef22f95c6eed7199ebe3ce7b0da90394a5..8974ecbdf42cba89af91a8bc375f07e102170ca9 100644 (file)
@@ -1776,28 +1776,32 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D,
   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;
index c0325cfa6c4b066292af42002ed2e2ff9c031297..363115d1844e5069b02d171b04bc5011e9eff0b7 100644 (file)
@@ -152,3 +152,26 @@ namespace PR6947 {
   }
 
 }
+
+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;
+  }
+
+}