Check and diagnose that objective-c objects may not be statically allocated.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42936 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 9d47375..b66c9f4 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -556,6 +556,11 @@
} else {
QualType R = GetTypeForDeclarator(D, S);
assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
+ if (R.getTypePtr()->isObjcInterfaceType()) {
+ Diag(D.getIdentifierLoc(), diag::err_statically_allocated_object,
+ D.getIdentifier()->getName());
+ InvalidDecl = true;
+ }
VarDecl *NewVD;
VarDecl::StorageClass SC;
@@ -1680,6 +1685,14 @@
}
}
}
+ /// A field cannot be an Objective-c object
+ if (FDTy->isObjcInterfaceType()) {
+ Diag(FD->getLocation(), diag::err_statically_allocated_object,
+ FD->getName());
+ FD->setInvalidDecl();
+ EnclosingDecl->setInvalidDecl();
+ continue;
+ }
// Keep track of the number of named members.
if (IdentifierInfo *II = FD->getIdentifier()) {
// Detect duplicate member names.