[cfe-commits] r73284 - in /cfe/trunk: lib/AST/DeclCXX.cpp test/SemaTemplate/instantiate-function-1.cpp
Anders Carlsson
andersca at mac.com
Fri Jun 12 19:59:33 PDT 2009
Author: andersca
Date: Fri Jun 12 21:59:33 2009
New Revision: 73284
URL: http://llvm.org/viewvc/llvm-project?rev=73284&view=rev
Log:
If a CXXRecordDecl is a class template, the 'this' type should be the injected class name type. Fixes pr4383.
Modified:
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=73284&r1=73283&r2=73284&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Fri Jun 12 21:59:33 2009
@@ -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();
}
Modified: cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp?rev=73284&r1=73283&r2=73284&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp Fri Jun 12 21:59:33 2009
@@ -140,7 +140,7 @@
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 @@
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; }
+};
More information about the cfe-commits
mailing list