r375124 - [ObjC] Add some additional test cases around pointer conversions.

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 17 08:18:59 PDT 2019


Author: jyknight
Date: Thu Oct 17 08:18:59 2019
New Revision: 375124

URL: http://llvm.org/viewvc/llvm-project?rev=375124&view=rev
Log:
[ObjC] Add some additional test cases around pointer conversions.

This is especially important for Objective-C++, which is entirely
missing this testing at the moment.

This annotates with "FIXME" the cases which I change in the next
patch -- I primarily wanted to document the current state of things so
that the effect of the code change is made clear.

Differential Revision: https://reviews.llvm.org/D67982

Added:
    cfe/trunk/test/SemaObjCXX/class-method-self.mm
    cfe/trunk/test/SemaObjCXX/comptypes-1.mm
    cfe/trunk/test/SemaObjCXX/comptypes-7.mm
Modified:
    cfe/trunk/test/SemaObjC/class-method-self.m
    cfe/trunk/test/SemaObjC/comptypes-1.m
    cfe/trunk/test/SemaObjC/comptypes-7.m
    cfe/trunk/test/SemaObjCXX/instancetype.mm

Modified: cfe/trunk/test/SemaObjC/class-method-self.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-method-self.m?rev=375124&r1=375123&r2=375124&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/class-method-self.m (original)
+++ cfe/trunk/test/SemaObjC/class-method-self.m Thu Oct 17 08:18:59 2019
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -verify -Wno-objc-root-class %s
 
-typedef struct objc_class *Class;
 @interface XX
 
 - (void)addObserver:(XX*)o; // expected-note 2{{passing argument to parameter 'o' here}}
@@ -23,4 +22,3 @@ static XX *obj;
   [obj addObserver:whatever]; // expected-warning {{incompatible pointer types sending 'Class' to parameter of type 'XX *'}}
 }
 @end
-

Modified: cfe/trunk/test/SemaObjC/comptypes-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/comptypes-1.m?rev=375124&r1=375123&r2=375124&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/comptypes-1.m (original)
+++ cfe/trunk/test/SemaObjC/comptypes-1.m Thu Oct 17 08:18:59 2019
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
 
 #define nil (void *)0;
-#define Nil (void *)0;
 
 extern void foo();
 
 @protocol MyProtocol
 - (void) foo;
++ (void) bar;
 @end
 
 @interface MyClass
@@ -22,7 +22,8 @@ int main()
   id<MyProtocol> obj_p = nil;
   MyClass *obj_c = nil;
   MyOtherClass *obj_cp = nil;
-  Class obj_C = Nil;
+  Class obj_C = nil;
+  Class<MyProtocol> obj_CP = nil;
 
   /* Assigning to an 'id' variable should never
      generate a warning.  */
@@ -30,12 +31,15 @@ int main()
   obj = obj_c;  /* Ok  */
   obj = obj_cp; /* Ok  */
   obj = obj_C;  /* Ok  */
-  
+  obj = obj_CP;  /* Ok  */
+
   /* Assigning to a 'MyClass *' variable should always generate a
      warning, unless done from an 'id'.  */
   obj_c = obj;    /* Ok */
-  obj_c = obj_cp; // // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'MyOtherClass *'}}
+  obj_c = obj_p;  // expected-warning {{assigning to 'MyClass *' from incompatible type 'id<MyProtocol>'}}
+  obj_c = obj_cp; // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'MyOtherClass *'}}
   obj_c = obj_C;  // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'Class'}}
+  obj_c = obj_CP; // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'Class<MyProtocol>'}}
 
   /* Assigning to an 'id<MyProtocol>' variable should generate a
      warning if done from a 'MyClass *' (which doesn't implement
@@ -45,6 +49,7 @@ int main()
   obj_p = obj_c;  // expected-warning {{assigning to 'id<MyProtocol>' from incompatible type 'MyClass *'}}
   obj_p = obj_cp; /* Ok  */
   obj_p = obj_C;  // expected-warning {{incompatible pointer types assigning to 'id<MyProtocol>' from 'Class'}}
+  obj_p = obj_CP; // FIXME -- should warn {{assigning to 'id<MyProtocol>' from incompatible type 'Class<MyProtocol>'}}
 
   /* Assigning to a 'MyOtherClass *' variable should always generate
      a warning, unless done from an 'id' or an 'id<MyProtocol>' (since
@@ -53,37 +58,67 @@ int main()
   obj_cp = obj_c;  // expected-warning {{incompatible pointer types assigning to 'MyOtherClass *' from 'MyClass *'}}
   obj_cp = obj_p;  /* Ok */
   obj_cp = obj_C;  // expected-warning {{incompatible pointer types assigning to 'MyOtherClass *' from 'Class'}}
+  obj_cp = obj_CP; // expected-warning {{incompatible pointer types assigning to 'MyOtherClass *' from 'Class<MyProtocol>'}}
+
+  obj_C = obj;     // Ok
+  obj_C = obj_p;   // expected-warning {{incompatible pointer types assigning to 'Class' from 'id<MyProtocol>'}}
+  obj_C = obj_c;   // expected-warning {{incompatible pointer types assigning to 'Class' from 'MyClass *'}}
+  obj_C = obj_cp;  // expected-warning {{incompatible pointer types assigning to 'Class' from 'MyOtherClass *'}}
+  obj_C = obj_CP;  // Ok
+
+  obj_CP = obj;     // Ok
+  obj_CP = obj_p;   // expected-warning {{assigning to 'Class<MyProtocol>' from incompatible type 'id<MyProtocol>'}}
+  obj_CP = obj_c;   // expected-warning {{incompatible pointer types assigning to 'Class<MyProtocol>' from 'MyClass *}}
+  obj_CP = obj_cp;  // expected-warning {{incompatible pointer types assigning to 'Class<MyProtocol>' from 'MyOtherClass *'}}
+  obj_CP = obj_C;   // Ok
 
   /* Any comparison involving an 'id' must be without warnings.  */
-  if (obj == obj_p) foo() ;  /* Ok  */ /*Bogus warning here in 2.95.4*/
-  if (obj_p == obj) foo() ;  /* Ok  */
-  if (obj == obj_c) foo() ;  /* Ok  */
-  if (obj_c == obj) foo() ;  /* Ok  */
-  if (obj == obj_cp) foo() ; /* Ok  */
-  if (obj_cp == obj) foo() ; /* Ok  */
-  if (obj == obj_C) foo() ;  /* Ok  */
-  if (obj_C == obj) foo() ;  /* Ok  */
+  if (obj == obj_p) foo();  /* Ok  */ /*Bogus warning here in 2.95.4*/
+  if (obj_p == obj) foo();  /* Ok  */
+  if (obj == obj_c) foo();  /* Ok  */
+  if (obj_c == obj) foo();  /* Ok  */
+  if (obj == obj_cp) foo(); /* Ok  */
+  if (obj_cp == obj) foo(); /* Ok  */
+  if (obj == obj_C) foo();  /* Ok  */
+  if (obj_C == obj) foo();  /* Ok  */
+  if (obj == obj_CP) foo(); /* Ok  */
+  if (obj_CP == obj) foo(); /* Ok  */
 
   /* Any comparison between 'MyClass *' and anything which is not an 'id'
      must generate a warning.  */
-  if (obj_p == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'MyClass *')}}
+  if (obj_c == obj_p) foo();  // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'id<MyProtocol>')}}
+  if (obj_p == obj_c) foo();  // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'MyClass *')}}
+
+  if (obj_c == obj_cp) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}}
+  if (obj_cp == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}}
 
-  if (obj_c == obj_cp) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}} 
-  if (obj_cp == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}}
+  if (obj_c == obj_C) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('MyClass *' and 'Class')}}
+  if (obj_C == obj_c) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'MyClass *')}}
 
-  if (obj_c == obj_C) foo() ;
-  if (obj_C == obj_c) foo() ;
+  if (obj_c == obj_CP) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'Class<MyProtocol>')}}
+  if (obj_CP == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('Class<MyProtocol>' and 'MyClass *')}}
 
   /* Any comparison between 'MyOtherClass *' (which implements
      MyProtocol) and an 'id' implementing MyProtocol are Ok.  */
-  if (obj_cp == obj_p) foo() ; /* Ok */
-  if (obj_p == obj_cp) foo() ; /* Ok */
+  if (obj_p == obj_cp) foo();  /* Ok */
+  if (obj_cp == obj_p) foo();  /* Ok */
+
+  if (obj_p == obj_C) foo();   // FIXME -- should warn {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class')}}
+  if (obj_C == obj_p) foo();   // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'id<MyProtocol>')}}
+
+  if (obj_p == obj_CP) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class<MyProtocol>')}}
+  if (obj_CP == obj_p) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('Class<MyProtocol>' and 'id<MyProtocol>')}}
+
+  /* Comparisons between MyOtherClass * and Class types is a warning */
+  if (obj_cp == obj_C) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('MyOtherClass *' and 'Class')}}
+  if (obj_C == obj_cp) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'MyOtherClass *')}}
 
+  if (obj_cp == obj_CP) foo(); // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'Class<MyProtocol>')}}
+  if (obj_CP == obj_cp) foo(); // expected-warning {{comparison of distinct pointer types ('Class<MyProtocol>' and 'MyOtherClass *')}}
 
-  if (obj_p == obj_C) foo() ;  
-  if (obj_C == obj_p) foo() ;
-  if (obj_cp == obj_C) foo() ;  
-  if (obj_C == obj_cp) foo() ;
+  /* Comparisons between a Class and a Class<MyProtocol> are ok */
+  if (obj_C == obj_CP) foo(); /* Ok */
+  if (obj_CP == obj_C) foo(); /* Ok */
 
   return 0;
 }

Modified: cfe/trunk/test/SemaObjC/comptypes-7.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/comptypes-7.m?rev=375124&r1=375123&r2=375124&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/comptypes-7.m (original)
+++ cfe/trunk/test/SemaObjC/comptypes-7.m Thu Oct 17 08:18:59 2019
@@ -1,7 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
 
 #define nil (void *)0;
-#define Nil (void *)0;
 
 extern void foo();
 
@@ -17,7 +16,7 @@ int main()
   id obj = nil;
   id <MyProtocol> obj_p = nil;
   MyClass *obj_c = nil;
-  Class obj_C = Nil;
+  Class obj_C = nil;
   
   int i = 0;
   int *j = nil;
@@ -66,8 +65,8 @@ int main()
   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')}}
 
-  Class bar1 = Nil;
-  Class <MyProtocol> bar = Nil;
+  Class bar1 = nil;
+  Class <MyProtocol> bar = nil;
   bar = bar1;
   bar1 = bar;
 

Added: cfe/trunk/test/SemaObjCXX/class-method-self.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/class-method-self.mm?rev=375124&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/class-method-self.mm (added)
+++ cfe/trunk/test/SemaObjCXX/class-method-self.mm Thu Oct 17 08:18:59 2019
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
+// FIXME: expected-no-diagnostics
+ at interface XX
+
+- (void)addObserver:(XX*)o; // FIXME -- should note 2{{passing argument to parameter 'o' here}}
+
+ at end
+
+ at interface YY
+
++ (void)classMethod;
+
+ at end
+
+ at implementation YY
+
+static XX *obj;
+
++ (void)classMethod {
+  [obj addObserver:self];     // FIXME -- should error {{cannot initialize a parameter of type 'XX *' with an lvalue of type 'Class'}}
+  Class whatever;
+  [obj addObserver:whatever]; // FIXME -- should error {{cannot initialize a parameter of type 'XX *' with an lvalue of type 'Class'}}
+}
+ at end
+

Added: cfe/trunk/test/SemaObjCXX/comptypes-1.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/comptypes-1.mm?rev=375124&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/comptypes-1.mm (added)
+++ cfe/trunk/test/SemaObjCXX/comptypes-1.mm Thu Oct 17 08:18:59 2019
@@ -0,0 +1,124 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+
+#define nil nullptr
+
+extern void foo();
+
+ at protocol MyProtocol
+- (void) foo;
++ (void) bar;
+ at end
+
+ at interface MyClass
+ at end
+
+ at interface MyOtherClass <MyProtocol>
+- (void) foo;
+ at end
+
+int main()
+{
+  id obj = nil;
+  id<MyProtocol> obj_p = nil;
+  MyClass *obj_c = nil;
+  MyOtherClass *obj_cp = nil;
+  Class obj_C = nil;
+  Class<MyProtocol> obj_CP = nil;
+
+  /* Assigning to an 'id' variable should never
+     generate a warning.  */
+  obj = obj_p;  /* Ok  */
+  obj = obj_c;  /* Ok  */
+  obj = obj_cp; /* Ok  */
+  obj = obj_C;  /* Ok  */
+  obj = obj_CP; /* Ok  */
+
+  /* Assigning to a 'MyClass *' variable should always generate a
+     warning, unless done from an 'id'.  */
+  obj_c = obj;    /* Ok */
+  obj_c = obj_p;  // expected-error {{assigning to 'MyClass *' from incompatible type 'id<MyProtocol>'}}
+  obj_c = obj_cp; // expected-error {{assigning to 'MyClass *' from incompatible type 'MyOtherClass *'}}
+  obj_c = obj_C;  // FIXME -- should error {{assigning to 'MyClass *' from incompatible type 'Class'}}
+  obj_c = obj_CP; // expected-error {{assigning to 'MyClass *' from incompatible type 'Class<MyProtocol>'}}
+
+  /* Assigning to an 'id<MyProtocol>' variable should generate a
+     warning if done from a 'MyClass *' (which doesn't implement
+     MyProtocol), but not from an 'id' or from a 'MyOtherClass *'
+     (which implements MyProtocol).  */
+  obj_p = obj;    /* Ok */
+  obj_p = obj_c;  // expected-error {{assigning to 'id<MyProtocol>' from incompatible type 'MyClass *'}}
+  obj_p = obj_cp; /* Ok  */
+  obj_p = obj_C;  // FIXME -- should error {{assigning to 'id<MyProtocol>' from incompatible type 'Class'}}
+  obj_p = obj_CP; // FIXME -- should error {{assigning to 'id<MyProtocol>' from incompatible type 'Class<MyProtocol>'}}
+
+  /* Assigning to a 'MyOtherClass *' variable should always generate
+     a warning, unless done from an 'id' or an 'id<MyProtocol>' (since
+     MyOtherClass implements MyProtocol).  */
+  obj_cp = obj;    /* Ok */
+  obj_cp = obj_c;  // expected-error {{assigning to 'MyOtherClass *' from incompatible type 'MyClass *'}}
+  obj_cp = obj_p;  /* Ok */
+  obj_cp = obj_C;  // FIXME -- should error {{assigning to 'MyOtherClass *' from incompatible type 'Class'}}
+  obj_cp = obj_CP; // expected-error {{assigning to 'MyOtherClass *' from incompatible type 'Class<MyProtocol>'}}
+
+  obj_C = obj;     // Ok
+  obj_C = obj_p;   // FIXME -- should error {{assigning to 'Class' from incompatible type 'id<MyProtocol>'}}
+  obj_C = obj_c;   // FIXME -- should error {{assigning to 'Class' from incompatible type 'MyClass *'}}
+  obj_C = obj_cp;  // FIXME -- should error {{assigning to 'Class' from incompatible type 'MyOtherClass *'}}
+  obj_C = obj_CP;  // Ok
+
+  obj_CP = obj;     // Ok
+  obj_CP = obj_p;   // expected-warning {{incompatible pointer types assigning to 'Class<MyProtocol>' from 'id<MyProtocol>'}} FIXME -- should error {{assigning to 'Class<MyProtocol>' from incompatible type 'id<MyProtocol>'}}
+  obj_CP = obj_c;   // expected-error {{assigning to 'Class<MyProtocol>' from incompatible type 'MyClass *}}
+  obj_CP = obj_cp;  // expected-error {{assigning to 'Class<MyProtocol>' from incompatible type 'MyOtherClass *'}}
+  obj_CP = obj_C;   // Ok
+
+  /* Any comparison involving an 'id' must be without warnings.  */
+  if (obj == obj_p) foo();  /* Ok  */ /*Bogus warning here in 2.95.4*/
+  if (obj_p == obj) foo();  /* Ok  */
+  if (obj == obj_c) foo();  /* Ok  */
+  if (obj_c == obj) foo();  /* Ok  */
+  if (obj == obj_cp) foo(); /* Ok  */
+  if (obj_cp == obj) foo(); /* Ok  */
+  if (obj == obj_C) foo();  /* Ok  */
+  if (obj_C == obj) foo();  /* Ok  */
+  if (obj == obj_CP) foo(); /* Ok  */
+  if (obj_CP == obj) foo(); /* Ok  */
+
+  /* Any comparison between 'MyClass *' and anything which is not an 'id'
+     must generate a warning.  */
+  if (obj_c == obj_p) foo();  // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'id<MyProtocol>')}}
+  if (obj_p == obj_c) foo();  // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'MyClass *')}}
+
+  if (obj_c == obj_cp) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}}
+  if (obj_cp == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}}
+
+  if (obj_c == obj_C) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('MyClass *' and 'Class')}}
+  if (obj_C == obj_c) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'MyClass *')}}
+
+  if (obj_c == obj_CP) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'Class<MyProtocol>')}}
+  if (obj_CP == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('Class<MyProtocol>' and 'MyClass *')}}
+
+  /* Any comparison between 'MyOtherClass *' (which implements
+     MyProtocol) and an 'id' implementing MyProtocol are Ok.  */
+  if (obj_p == obj_cp) foo();  /* Ok */
+  if (obj_cp == obj_p) foo();  /* Ok */
+
+  if (obj_p == obj_C) foo();   // FIXME -- should warn {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class')}}
+  if (obj_C == obj_p) foo();   // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'id<MyProtocol>')}}
+
+  if (obj_p == obj_CP) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class<MyProtocol>')}}
+  if (obj_CP == obj_p) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('Class<MyProtocol>' and 'id<MyProtocol>')}}
+
+  /* Comparisons between MyOtherClass * and Class types is a warning */
+  if (obj_cp == obj_C) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('MyOtherClass *' and 'Class')}}
+  if (obj_C == obj_cp) foo();  // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'MyOtherClass *')}}
+
+  if (obj_cp == obj_CP) foo(); // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'Class<MyProtocol>')}}
+  if (obj_CP == obj_cp) foo(); // expected-warning {{comparison of distinct pointer types ('Class<MyProtocol>' and 'MyOtherClass *')}}
+
+  /* Comparisons between a Class and a Class<MyProtocol> are ok */
+  if (obj_C == obj_CP) foo(); /* Ok */
+  if (obj_CP == obj_C) foo(); /* Ok */
+
+  return 0;
+}

Added: cfe/trunk/test/SemaObjCXX/comptypes-7.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/comptypes-7.mm?rev=375124&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/comptypes-7.mm (added)
+++ cfe/trunk/test/SemaObjCXX/comptypes-7.mm Thu Oct 17 08:18:59 2019
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+
+#define nil nullptr
+
+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 errors.  */
+
+  obj = i; // expected-error {{assigning to 'id' from incompatible type 'int'}}
+  obj = j; // expected-error {{assigning to 'id' from incompatible type 'int *'}}
+
+  obj_p = i; // expected-error {{assigning to 'id<MyProtocol>' from incompatible type 'int'}}
+  obj_p = j; // expected-error {{assigning to 'id<MyProtocol>' from incompatible type 'int *'}}
+
+  obj_c = i; // expected-error {{assigning to 'MyClass *' from incompatible type 'int'}}
+  obj_c = j; // expected-error {{assigning to 'MyClass *' from incompatible type 'int *'}}
+
+  obj_C = i; // expected-error {{assigning to 'Class' from incompatible type 'int'}}
+  obj_C = j; // expected-error {{assigning to 'Class' from incompatible type 'int *'}}
+
+  i = obj;   // expected-error {{assigning to 'int' from incompatible type 'id'}}
+  i = obj_p; // expected-error {{assigning to 'int' from incompatible type 'id<MyProtocol>'}}
+  i = obj_c; // expected-error {{assigning to 'int' from incompatible type 'MyClass *'}}
+  i = obj_C; // expected-error {{assigning to 'int' from incompatible type 'Class'}}
+
+  j = obj;   // expected-error {{assigning to 'int *' from incompatible type 'id'}}
+  j = obj_p; // expected-error {{assigning to 'int *' from incompatible type 'id<MyProtocol>'}}
+  j = obj_c; // expected-error {{assigning to 'int *' from incompatible type 'MyClass *'}}
+  j = obj_C; // expected-error {{assigning to 'int *' from incompatible type 'Class'}}
+
+  if (obj == i) foo() ; // expected-error {{comparison between pointer and integer ('id' and 'int')}}
+  if (i == obj) foo() ; // expected-error {{comparison between pointer and integer ('int' and 'id')}}
+  if (obj == j) foo() ; // expected-error {{invalid operands to binary expression ('id' and 'int *')}}
+  if (j == obj) foo() ; // expected-error {{invalid operands to binary expression ('int *' and 'id')}}
+
+  if (obj_c == i) foo() ; // expected-error {{comparison between pointer and integer ('MyClass *' and 'int')}}
+  if (i == obj_c) foo() ; // expected-error {{comparison between pointer and integer ('int' and 'MyClass *')}}
+  if (obj_c == j) foo() ; // expected-error {{invalid operands to binary expression ('MyClass *' and 'int *')}}
+  if (j == obj_c) foo() ; // expected-error {{invalid operands to binary expression ('int *' and 'MyClass *')}}
+
+  if (obj_p == i) foo() ; // expected-error {{comparison between pointer and integer ('id<MyProtocol>' and 'int')}}
+  if (i == obj_p) foo() ; // expected-error {{comparison between pointer and integer ('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-error {{comparison between pointer and integer ('Class' and 'int')}}
+  if (i == obj_C) foo() ; // expected-error {{comparison between pointer and integer ('int' and 'Class')}}
+  if (obj_C == j) foo() ; // expected-error {{invalid operands to binary expression ('Class' and 'int *')}}
+  if (j == obj_C) foo() ; // expected-error {{invalid operands to binary expression ('int *' and 'Class')}}
+
+  Class bar1 = nil;
+  Class <MyProtocol> bar = nil;
+  bar = bar1;
+  bar1 = bar;
+
+  return 0;
+}

Modified: cfe/trunk/test/SemaObjCXX/instancetype.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/instancetype.mm?rev=375124&r1=375123&r2=375124&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/instancetype.mm (original)
+++ cfe/trunk/test/SemaObjCXX/instancetype.mm Thu Oct 17 08:18:59 2019
@@ -5,7 +5,7 @@
 #endif
 
 @interface Root
-+ (instancetype)alloc;
++ (instancetype)alloc; // FIXME -- should note {{explicitly declared 'instancetype'}}
 - (instancetype)init; // expected-note{{overridden method is part of the 'init' method family}}
 - (instancetype)self; // expected-note {{explicitly declared 'instancetype'}}
 - (Class)class;
@@ -143,7 +143,7 @@ void test_instancetype_narrow_method_sea
 
 @implementation Subclass4
 + (id)alloc {
-  return self; // FIXME: we accept this in ObjC++ but not ObjC?
+  return self; // FIXME -- should error{{cannot initialize return object of type 'Subclass4 *' with an lvalue of type 'Class'}}
 }
 
 - (Subclass3 *)init { return 0; } // don't complain: we lost the related return type




More information about the cfe-commits mailing list