[cfe-commits] r72568 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-declref.cpp

Douglas Gregor dgregor at apple.com
Fri May 29 07:25:09 PDT 2009


Author: dgregor
Date: Fri May 29 09:25:00 2009
New Revision: 72568

URL: http://llvm.org/viewvc/llvm-project?rev=72568&view=rev
Log:
Now that we have declared/defined tag types within DeclGroups,
instantiation of tags local to member functions of class templates
(and, eventually, function templates) works when the tag is defined as
part of the decl-specifier-seq, e.g.,

  struct S { T x, y; } s1;

Also, make sure that we don't try to default-initialize a dependent
type.


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

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri May 29 09:25:00 2009
@@ -2701,7 +2701,7 @@
       if (const ArrayType *Array = Context.getAsArrayType(Type))
         InitType = Array->getElementType();
       if ((!Var->hasExternalStorage() && !Var->isExternC(Context)) &&
-           InitType->isRecordType()) {
+          InitType->isRecordType() && !InitType->isDependentType()) {
         CXXRecordDecl *RD = 
           cast<CXXRecordDecl>(InitType->getAsRecordType()->getDecl());
         CXXConstructorDecl *Constructor = 0;

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri May 29 09:25:00 2009
@@ -97,8 +97,6 @@
     Typedef->setInvalidDecl();
 
   Owner->addDecl(SemaRef.Context, Typedef);
-  if (Owner->isFunctionOrMethod())
-    SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Typedef);
     
   return Typedef;
 }
@@ -214,8 +212,6 @@
   Enum->setInstantiationOfMemberEnum(D);
   Enum->setAccess(D->getAccess());
   Owner->addDecl(SemaRef.Context, Enum);
-  if (Owner->isFunctionOrMethod())
-    SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Enum);
   Enum->startDefinition();
 
   llvm::SmallVector<Sema::DeclPtrTy, 16> Enumerators;
@@ -281,8 +277,6 @@
     Record->setInstantiationOfMemberClass(D);
 
   Owner->addDecl(SemaRef.Context, Record);
-  if (Owner->isFunctionOrMethod())
-    SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Record);
   return Record;
 }
 

Modified: cfe/trunk/test/SemaTemplate/instantiate-declref.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-declref.cpp?rev=72568&r1=72567&r2=72568&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-declref.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-declref.cpp Fri May 29 09:25:00 2009
@@ -40,13 +40,20 @@
 
 namespace N2 {
   struct Outer2 {
-    template<typename T>
+    template<typename T, typename U = T>
     struct Inner {
       void foo() {
         enum { K1Val = sizeof(T) } k1;
-        enum K2 { K2Val = sizeof(T)*2 };
+        enum K2 { K2Val = sizeof(T)*2 } k2a;
 
-        K2 k2 = K2Val;
+        K2 k2b = K2Val;
+
+        struct S { T x, y; } s1;
+        struct { U x, y; } s2;
+        s1.x = s2.x; // expected-error{{incompatible}}
+
+        typedef T type;
+        type t2 = s1.x;
 
         Inner i1;
         i1.foo();
@@ -57,4 +64,5 @@
   };
 }
 
-// FIXME: template struct N2::Outer2::Inner<float>;
+template struct N2::Outer2::Inner<float>;
+template struct N2::Outer2::Inner<int*, float*>; // expected-note{{instantiation}}





More information about the cfe-commits mailing list