From 43477ca46792311640cf29b7cff731e29bebb146 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 18 Aug 2008 22:49:54 +0000 Subject: [PATCH] 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 --- include/clang/Basic/DiagnosticKinds.def | 2 ++ lib/Sema/SemaType.cpp | 4 ++++ test/SemaObjC/interface-1.m | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 30efa85981..6eeaffa683 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -406,6 +406,8 @@ DIAG(err_objc_missing_end, ERROR, "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 eafaae5d87..820a1c85f0 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -338,7 +338,11 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { 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 d93f29c4b6..31706653f5 100644 --- a/test/SemaObjC/interface-1.m +++ b/test/SemaObjC/interface-1.m @@ -15,3 +15,13 @@ NSObject // expected-error {{cannot find interface declaration for 'NSObject @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; +} + -- 2.40.0