Home | History | Annotate | Download | only in SemaObjC
      1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
      2 
      3 @protocol NSObject
      4 @end
      5 @interface NSObject <NSObject> {
      6 }
      7 @end
      8 @interface NSString : NSObject
      9 @end
     10 void __setRetained(id *ivar, id value, NSObject **o) {
     11     *ivar = value;
     12 }
     13 static NSString *_logProcessPrefix = 0;
     14 void func() {
     15   __setRetained(&_logProcessPrefix, _logProcessPrefix, &_logProcessPrefix);
     16 }
     17 @implementation NSObject (ScopeAdditions)
     18 + (void)setObjectLogProcessPrefix:(NSString *)processPrefix {
     19     __setRetained(&_logProcessPrefix, processPrefix, &_logProcessPrefix);
     20 }
     21 @end
     22 
     23 @class Derived;
     24 
     25 NSObject *ExternFunc (NSObject *filePath, NSObject *key);
     26 typedef id FuncSignature (NSObject *arg1, Derived *arg2);
     27 
     28 @interface Derived: NSObject
     29 + (void)registerFunc:(FuncSignature *)function; // expected-note{{passing argument to parameter 'function' here}}
     30 @end
     31 
     32 void foo(void)
     33 {
     34   // GCC currently allows this (it has some fiarly new support for covariant return types and contravariant argument types).
     35   // Since registerFunc: expects a Derived object as it's second argument, I don't know why this would be legal.
     36   [Derived registerFunc: ExternFunc];  // expected-warning{{incompatible pointer types sending 'NSObject *(NSObject *, NSObject *)' to parameter of type 'FuncSignature *'}}
     37 }
     38 
     39 // rdar://10751015
     40 @protocol NSCopying @end
     41 @interface I
     42 - (void) Meth : (id <NSCopying>)aKey; // expected-note {{passing argument to parameter 'aKey' here}}
     43 @end
     44 
     45 @class ForwarClass; // expected-note 3 {{conformance of forward class ForwarClass to protocol NSCopying can not be confirmed}}
     46 
     47 ForwarClass *Test10751015 (I* pi, ForwarClass *ns_forward) {
     48 
     49   [pi Meth : ns_forward ]; // expected-warning {{sending 'ForwarClass *' to parameter of incompatible type 'id<NSCopying>'}}
     50 
     51   id <NSCopying> id_ns = ns_forward; // expected-warning {{initializing 'id<NSCopying>' with an expression of incompatible type 'ForwarClass *'}}
     52 
     53   return id_ns; // expected-warning {{returning 'id<NSCopying>' from a function with incompatible result type 'ForwarClass *'}}
     54 }
     55