]> granicus.if.org Git - clang/commitdiff
warn when someone tries to make an array of ObjC interfaces instead of array
authorChris Lattner <sabre@nondot.org>
Mon, 18 Aug 2008 22:49:54 +0000 (22:49 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 18 Aug 2008 22:49:54 +0000 (22:49 +0000)
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
lib/Sema/SemaType.cpp
test/SemaObjC/interface-1.m

index 30efa859816975e7eaf6fd0f3f7a74be141e3db9..6eeaffa68356f8b6a7a144babfd2e49a63bc3717 100644 (file)
@@ -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")
index eafaae5d872bfbb49eb8a141af7068a662088b1d..820a1c85f06ab5478fa834c7267a708034ae8aeb 100644 (file)
@@ -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, 
index d93f29c4b6e29b4f2c11073349073dcbffb3e315..31706653f5943fd0628de07f830c6b3e192b3f71 100644 (file)
@@ -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;
+}
+