warn when someone tries to make an array of ObjC interfaces instead of array
of pointers to them. rdar://4304469
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54953 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index 30efa85..6eeaffa 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -406,6 +406,8 @@
"missing @end")
DIAG(warn_objc_protocol_qualifier_missing_id, WARNING,
"protocol qualifiers without 'id' is archaic")
+DIAG(warn_objc_array_of_interfaces, WARNING,
+ "array of interface '%0' should probably be array of pointers")
DIAG(err_objc_illegal_visibility_spec, ERROR,
"illegal visibility specification")
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index eafaae5..820a1c8 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -338,7 +338,11 @@
T = Context.IntTy;
D.setInvalidType(true);
}
+ } else if (T->isObjCInterfaceType()) {
+ Diag(DeclType.Loc, diag::warn_objc_array_of_interfaces,
+ T.getAsString());
}
+
// C99 6.7.5.2p1: The size expression shall have integer type.
if (ArraySize && !ArraySize->getType()->isIntegerType()) {
Diag(ArraySize->getLocStart(), diag::err_array_size_non_int,
diff --git a/test/SemaObjC/interface-1.m b/test/SemaObjC/interface-1.m
index d93f29c..3170665 100644
--- a/test/SemaObjC/interface-1.m
+++ b/test/SemaObjC/interface-1.m
@@ -15,3 +15,13 @@
@end
+// rdar://4304469
+@interface INT1
+@end
+
+void test2() {
+ INT1 b[3]; // expected-warning {{array of interface 'INT1' should probably be array of pointers}}
+ INT1 *c = &b[0];
+ ++c;
+}
+