]> granicus.if.org Git - clang/commitdiff
If a CXXRecordDecl is a class template, the 'this' type should be the injected class...
authorAnders Carlsson <andersca@mac.com>
Sat, 13 Jun 2009 02:59:33 +0000 (02:59 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 13 Jun 2009 02:59:33 +0000 (02:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73284 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclCXX.cpp
test/SemaTemplate/instantiate-function-1.cpp

index 94daf484458a3f08d0a987973c37c6c85e45a93e..8430da2be6b133edd904683ef2e85013779a895c 100644 (file)
@@ -260,7 +260,12 @@ QualType CXXMethodDecl::getThisType(ASTContext &C) const {
   // the type of this is const volatile X*.
 
   assert(isInstance() && "No 'this' for static methods!");
-  QualType ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>(getParent()));
+
+  QualType ClassTy;
+  if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate())
+    ClassTy = TD->getInjectedClassNameType(C);
+  else
+    ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>(getParent()));
   ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers());
   return C.getPointerType(ClassTy).withConst();
 }
index 5b3a6d998404263d3f9e21835dd5898662ed1a69..023cc5437f69e28c86263e05d4de6bf66d110219 100644 (file)
@@ -140,7 +140,7 @@ template<typename T> struct Member0 {
     tp->f;
 
     this->f;
-    this.f; // expected-error{{member reference base type 'struct Member0 *const' is not a structure or union}}
+    this.f; // expected-error{{member reference base type 'Member0<T> *const' is not a structure or union}}
   }
 };
 
@@ -209,3 +209,9 @@ struct Abstract {
 template struct TryCatch0<int>; // okay
 template struct TryCatch0<Incomplete*>; // expected-note{{instantiation}}
 template struct TryCatch0<Abstract>; // expected-note{{instantiation}}
+
+// PR4383
+template<typename T> struct X;
+template<typename T> struct Y : public X<T> {
+  Y& x() { return *this; }
+};