[cfe-commits] r80397 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-anonymous-union.cpp
Douglas Gregor
dgregor at apple.com
Fri Aug 28 15:03:52 PDT 2009
Author: dgregor
Date: Fri Aug 28 17:03:51 2009
New Revision: 80397
URL: http://llvm.org/viewvc/llvm-project?rev=80397&view=rev
Log:
Don't crash when instantiating templates containing anonymous structs/unions
Added:
cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=80397&r1=80396&r2=80397&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Aug 28 17:03:51 2009
@@ -1117,23 +1117,35 @@
if (D->getKind() != Other->getKind())
return false;
- if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other))
- return Record->getInstantiatedFromMemberClass()->getCanonicalDecl()
- == D->getCanonicalDecl();
-
- 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 (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 (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) &&
Added: cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp?rev=80397&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp Fri Aug 28 17:03:51 2009
@@ -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;
+
More information about the cfe-commits
mailing list