Don't crash when instantiating templates containing anonymous structs/unions

llvm-svn: 80397
This commit is contained in:
Douglas Gregor 2009-08-28 22:03:51 +00:00
parent 11395b66c6
commit f3db003358
2 changed files with 34 additions and 14 deletions

View File

@ -1117,23 +1117,35 @@ static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) {
if (D->getKind() != Other->getKind())
return false;
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other))
return Record->getInstantiatedFromMemberClass()->getCanonicalDecl()
== D->getCanonicalDecl();
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other)) {
if (CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass())
return Pattern->getCanonicalDecl() == D->getCanonicalDecl();
else
return false;
}
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other)) {
if (FunctionDecl *Pattern = Function->getInstantiatedFromMemberFunction())
return Pattern->getCanonicalDecl() == D->getCanonicalDecl();
else
return false;
}
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other))
return Function->getInstantiatedFromMemberFunction()->getCanonicalDecl()
== D->getCanonicalDecl();
if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other))
return Enum->getInstantiatedFromMemberEnum()->getCanonicalDecl()
== D->getCanonicalDecl();
if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other)) {
if (EnumDecl *Pattern = Enum->getInstantiatedFromMemberEnum())
return Pattern->getCanonicalDecl() == D->getCanonicalDecl();
else
return false;
}
if (VarDecl *Var = dyn_cast<VarDecl>(Other))
if (Var->isStaticDataMember())
return Var->getInstantiatedFromStaticDataMember()->getCanonicalDecl()
== D->getCanonicalDecl();
if (Var->isStaticDataMember()) {
if (VarDecl *Pattern = Var->getInstantiatedFromStaticDataMember())
return Pattern->getCanonicalDecl() == D->getCanonicalDecl();
else
return false;
}
// FIXME: How can we find instantiations of anonymous unions?
return D->getDeclName() && isa<NamedDecl>(Other) &&

View File

@ -0,0 +1,8 @@
// RUN: clang-cc -fsyntax-only %s
// FIXME: We need to test anonymous structs/unions in templates for real.
template <typename T> class A { struct { }; };
A<int> a0;