[cfe-commits] r102691 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/Decl.cpp test/SemaTemplate/injected-class-name.cpp
Douglas Gregor
dgregor at apple.com
Thu Apr 29 21:39:27 PDT 2010
Author: dgregor
Date: Thu Apr 29 23:39:27 2010
New Revision: 102691
URL: http://llvm.org/viewvc/llvm-project?rev=102691&view=rev
Log:
When we start the definition of a class template, set the
InjectedClassNameType's Decl to point at the definition. It's a little
messy, but we do the same thing with classes and their record types,
since much of Clang expects that the TagDecl* one gets out of a type
is the definition. Fixes several Boost.Proto failures.
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/SemaTemplate/injected-class-name.cpp
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=102691&r1=102690&r2=102691&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Apr 29 23:39:27 2010
@@ -2566,6 +2566,7 @@
QualType InjectedType;
friend class ASTContext; // ASTContext creates these.
+ friend class TagDecl; // TagDecl mutilates the Decl
InjectedClassNameType(CXXRecordDecl *D, QualType TST)
: Type(InjectedClassName, QualType(), true),
Decl(D), InjectedType(TST) {
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=102691&r1=102690&r2=102691&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Apr 29 23:39:27 2010
@@ -1479,6 +1479,10 @@
if (TagType *TagT = const_cast<TagType *>(TypeForDecl->getAs<TagType>())) {
TagT->decl.setPointer(this);
TagT->decl.setInt(1);
+ } else if (InjectedClassNameType *Injected
+ = const_cast<InjectedClassNameType *>(
+ TypeForDecl->getAs<InjectedClassNameType>())) {
+ Injected->Decl = cast<CXXRecordDecl>(this);
}
if (isa<CXXRecordDecl>(this)) {
@@ -1500,6 +1504,11 @@
assert(TagT->decl.getPointer() == this &&
"Attempt to redefine a tag definition?");
TagT->decl.setInt(0);
+ } else if (InjectedClassNameType *Injected
+ = const_cast<InjectedClassNameType *>(
+ TypeForDecl->getAs<InjectedClassNameType>())) {
+ assert(Injected->Decl == this &&
+ "Attempt to redefine a class template definition?");
}
}
Modified: cfe/trunk/test/SemaTemplate/injected-class-name.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/injected-class-name.cpp?rev=102691&r1=102690&r2=102691&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/injected-class-name.cpp (original)
+++ cfe/trunk/test/SemaTemplate/injected-class-name.cpp Thu Apr 29 23:39:27 2010
@@ -48,3 +48,15 @@
};
template class A<int>;
}
+
+namespace ForwardDecls {
+ template<typename T>
+ struct X;
+
+ template<typename T>
+ struct X {
+ typedef T foo;
+ typedef X<T> xt;
+ typename xt::foo *t;
+ };
+}
More information about the cfe-commits
mailing list