If a CXXRecordDecl is a class template, the 'this' type should be the injected class name type. Fixes pr4383.
llvm-svn: 73284
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 94daf48..8430da2 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -260,7 +260,12 @@
// 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();
}