Skip to content
Snippets Groups Projects
Commit f3db0033 authored by Douglas Gregor's avatar Douglas Gregor
Browse files

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

llvm-svn: 80397
parent 11395b66
No related branches found
No related tags found
No related merge requests found
...@@ -1117,23 +1117,35 @@ static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) { ...@@ -1117,23 +1117,35 @@ static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) {
if (D->getKind() != Other->getKind()) if (D->getKind() != Other->getKind())
return false; return false;
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other)) if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other)) {
return Record->getInstantiatedFromMemberClass()->getCanonicalDecl() if (CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass())
== D->getCanonicalDecl(); return Pattern->getCanonicalDecl() == D->getCanonicalDecl();
else
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other)) return false;
return Function->getInstantiatedFromMemberFunction()->getCanonicalDecl() }
== D->getCanonicalDecl();
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other)) {
if (FunctionDecl *Pattern = Function->getInstantiatedFromMemberFunction())
return Pattern->getCanonicalDecl() == D->getCanonicalDecl();
else
return false;
}
if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other)) if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other)) {
return Enum->getInstantiatedFromMemberEnum()->getCanonicalDecl() if (EnumDecl *Pattern = Enum->getInstantiatedFromMemberEnum())
== D->getCanonicalDecl(); return Pattern->getCanonicalDecl() == D->getCanonicalDecl();
else
return false;
}
if (VarDecl *Var = dyn_cast<VarDecl>(Other)) if (VarDecl *Var = dyn_cast<VarDecl>(Other))
if (Var->isStaticDataMember()) if (Var->isStaticDataMember()) {
return Var->getInstantiatedFromStaticDataMember()->getCanonicalDecl() if (VarDecl *Pattern = Var->getInstantiatedFromStaticDataMember())
== D->getCanonicalDecl(); return Pattern->getCanonicalDecl() == D->getCanonicalDecl();
else
return false;
}
// FIXME: How can we find instantiations of anonymous unions? // FIXME: How can we find instantiations of anonymous unions?
return D->getDeclName() && isa<NamedDecl>(Other) && return D->getDeclName() && isa<NamedDecl>(Other) &&
......
// 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;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment