Hello,

This patch modifies Sema to store the unresolved class type
in MemberPointerType's Class field, and fixes a bug where an
assertion would fail if the last element of a member pointer type's
nested-name-specifier is an identifier.

Thanks,
-- 
Peter
Index: test/CodeGenCXX/ptr-to-datamember.cpp
===================================================================
--- test/CodeGenCXX/ptr-to-datamember.cpp	(revision 85576)
+++ test/CodeGenCXX/ptr-to-datamember.cpp	(working copy)
@@ -32,6 +32,15 @@
   F Af;
 }; 
 
+template <typename T> struct TT {
+  int T::t::*pti;
+};
+
+struct I {
+  typedef I t;
+  int x;
+};
+
 void pr(const F& b) {
   printf(" %d %f\n", b.iF, b.fF);
 }
@@ -69,9 +78,12 @@
 int main() 
 {
   A a1;
+  TT<I> tt;
+  I i;
   int A::* pa = &A::Ai;
   float A::* pf = &A::f;
   double A::* pd = &A::d;
+  tt.pti = &I::x;
   printf("%d %d %d\n", &A::Ai, &A::f, &A::d);
   printf("%d\n", &A::B::iB);
   printf("%d\n", &A::B1::iB1);
@@ -81,6 +93,7 @@
   printf("%d\n", &A::B::V::iV);
   printf("%d\n", &A::B1::V::iV);
   printf("%d, %f, %f  \n", a1.*pa, a1.*pf, a1.*pd);
+  printf("%d\n", i.*tt.pti);
   test_aggr_pdata(a1);
   test_aggr_pdata_1(&a1);
 }
Index: lib/CodeGen/CGCXX.cpp
===================================================================
--- lib/CodeGen/CGCXX.cpp	(revision 85576)
+++ lib/CodeGen/CGCXX.cpp	(working copy)
@@ -286,7 +286,7 @@
   const FunctionProtoType *FPT = 
     MPT->getPointeeType()->getAs<FunctionProtoType>();
   const CXXRecordDecl *RD = 
-    cast<CXXRecordDecl>(cast<RecordType>(MPT->getClass())->getDecl());
+    cast<CXXRecordDecl>(MPT->getClass()->getAs<RecordType>()->getDecl());
 
   const llvm::FunctionType *FTy = 
     CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(RD, FPT),
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp	(revision 85576)
+++ lib/Sema/SemaType.cpp	(working copy)
@@ -1190,15 +1190,20 @@
       }
       // The scope spec must refer to a class, or be dependent.
       QualType ClsType;
-      if (isDependentScopeSpecifier(DeclType.Mem.Scope())) {
+      if (isDependentScopeSpecifier(DeclType.Mem.Scope())
+       || dyn_cast_or_null<CXXRecordDecl>(computeDeclContext(DeclType.Mem.Scope()))) {
         NestedNameSpecifier *NNS
           = (NestedNameSpecifier *)DeclType.Mem.Scope().getScopeRep();
-        assert(NNS->getAsType() && "Nested-name-specifier must name a type");
-        ClsType = QualType(NNS->getAsType(), 0);
-      } else if (CXXRecordDecl *RD
-                   = dyn_cast_or_null<CXXRecordDecl>(
-                                    computeDeclContext(DeclType.Mem.Scope()))) {
-        ClsType = Context.getTagDeclType(RD);
+        NestedNameSpecifier *NNSPrefix = NNS->getPrefix();
+        if (Type *NNSType = NNS->getAsType()) {
+          ClsType = QualType(NNSType, 0);
+          if (NNSPrefix)
+            ClsType = Context.getQualifiedNameType(NNSPrefix, ClsType);
+        } else if (IdentifierInfo *NNSII = NNS->getAsIdentifier()) {
+          ClsType = Context.getTypenameType(NNSPrefix, NNSII);
+        } else {
+          assert(0 && "Nested-name-specifier must name a type");
+        }
       } else {
         Diag(DeclType.Mem.Scope().getBeginLoc(),
              diag::err_illegal_decl_mempointer_in_nonclass)
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp	(revision 85576)
+++ lib/AST/ASTContext.cpp	(working copy)
@@ -1374,7 +1374,7 @@
   // If the pointee or class type isn't canonical, this won't be a canonical
   // type either, so fill in the canonical type field.
   QualType Canonical;
-  if (!T.isCanonical()) {
+  if (!T.isCanonical() || !Cls->isCanonicalUnqualified()) {
     Canonical = getMemberPointerType(getCanonicalType(T),getCanonicalType(Cls));
 
     // Get the new insert position for the node we care about.

Attachment: signature.asc
Description: Digital signature

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to