From: Anders Carlsson Date: Sat, 13 Jun 2009 02:59:33 +0000 (+0000) Subject: If a CXXRecordDecl is a class template, the 'this' type should be the injected class... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=31a08752eda39ca17154538e2f2587f8d339a1fa;p=clang If a CXXRecordDecl is a class template, the 'this' type should be the injected class name type. Fixes pr4383. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73284 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 94daf48445..8430da2be6 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -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(getParent())); + + QualType ClassTy; + if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate()) + ClassTy = TD->getInjectedClassNameType(C); + else + ClassTy = C.getTagDeclType(const_cast(getParent())); ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers()); return C.getPointerType(ClassTy).withConst(); } diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp index 5b3a6d9984..023cc5437f 100644 --- a/test/SemaTemplate/instantiate-function-1.cpp +++ b/test/SemaTemplate/instantiate-function-1.cpp @@ -140,7 +140,7 @@ template 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 *const' is not a structure or union}} } }; @@ -209,3 +209,9 @@ struct Abstract { template struct TryCatch0; // okay template struct TryCatch0; // expected-note{{instantiation}} template struct TryCatch0; // expected-note{{instantiation}} + +// PR4383 +template struct X; +template struct Y : public X { + Y& x() { return *this; } +};