[cfe-commits] r45302 - /cfe/trunk/test/Sema/objc-comptypes-7.m

Fariborz Jahanian fjahanian at apple.com
Fri Dec 21 16:17:49 PST 2007


Author: fjahanian
Date: Fri Dec 21 18:17:49 2007
New Revision: 45302

URL: http://llvm.org/viewvc/llvm-project?rev=45302&view=rev
Log:
Another test case, testing a variety of objective-c type comparisons.

Added:
    cfe/trunk/test/Sema/objc-comptypes-7.m

Added: cfe/trunk/test/Sema/objc-comptypes-7.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-comptypes-7.m?rev=45302&view=auto

==============================================================================
--- cfe/trunk/test/Sema/objc-comptypes-7.m (added)
+++ cfe/trunk/test/Sema/objc-comptypes-7.m Fri Dec 21 18:17:49 2007
@@ -0,0 +1,69 @@
+// RUN: clang -fsyntax-only -verify %s
+
+#include <objc/objc.h>
+
+extern void foo();
+
+ at protocol MyProtocol
+- (void) method;
+ at end
+
+ at interface MyClass
+ at end
+
+int main()
+{
+  id obj = nil;
+  id <MyProtocol> obj_p = nil;
+  MyClass *obj_c = nil;
+  Class obj_C = Nil;
+  
+  int i = 0;
+  int *j = nil;
+
+  /* These should all generate warnings.  */
+  
+  obj = i; // expected-warning {{incompatible types assigning 'int' to 'id'}}
+  obj = j; // expected-warning {{incompatible pointer types assigning 'int *' to 'id'}}
+
+  obj_p = i; // expected-error {{incompatible types assigning 'int' to 'id<MyProtocol>' }}
+  obj_p = j; // expected-error {{incompatible types assigning 'int *' to 'id<MyProtocol>'}}
+  
+  obj_c = i; // expected-warning {{incompatible types assigning 'int' to 'MyClass *'}}
+  obj_c = j; // expected-warning {{incompatible pointer types assigning 'int *' to 'MyClass *'}}
+
+  obj_C = i; // expected-warning {{incompatible types assigning 'int' to 'Class'}}
+  obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *' to 'Class'}}
+  
+  i = obj;   // expected-warning {{incompatible types assigning 'id' to 'int'}}
+  i = obj_p; // expected-error {{incompatible types assigning 'id<MyProtocol>' to 'int'}}
+  i = obj_c; // expected-warning {{incompatible types assigning 'MyClass *' to 'int'}}
+  i = obj_C; // expected-warning {{incompatible types assigning 'Class' to 'int'}}
+  
+  j = obj;   // expected-warning {{incompatible pointer types assigning 'id' to 'int *'}}
+  j = obj_p; // expected-error {{incompatible types assigning 'id<MyProtocol>' to 'int *'}}
+  j = obj_c; // expected-warning {{incompatible pointer types assigning 'MyClass *' to 'int *'}}
+  j = obj_C; // expected-warning {{incompatible pointer types assigning 'Class' to 'int *'}}
+  
+  if (obj == i) foo() ; // expected-warning {{comparison between pointer and integer ('id' and 'int')}}
+  if (i == obj) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id')}}
+  if (obj == j) foo() ; // expected-warning {{comparison of distinct pointer types ('id' and 'int *')}}
+  if (j == obj) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'id')}}
+
+  if (obj_c == i) foo() ; // expected-warning {{comparison between pointer and integer ('MyClass *' and 'int')}}
+  if (i == obj_c) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'MyClass *')}}
+  if (obj_c == j) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'int *')}}
+  if (j == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'MyClass *')}}
+
+  if (obj_p == i) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'int')}}
+  if (i == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('int' and 'id<MyProtocol>')}}
+  if (obj_p == j) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'int *')}}
+  if (j == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('int *' and 'id<MyProtocol>')}}
+
+  if (obj_C == i) foo() ; // expected-warning {{comparison between pointer and integer ('Class' and 'int')}}
+  if (i == obj_C) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'Class')}}
+  if (obj_C == j) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'int *')}}
+  if (j == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'Class')}}
+
+  return 0;
+}





More information about the cfe-commits mailing list