File: comptypes-legal.m

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (54 lines) | stat: -rw-r--r-- 2,073 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s

@protocol NSObject
@end
@interface NSObject <NSObject> {
}
@end
@interface NSString : NSObject
@end
void __setRetained(id *ivar, id value, NSObject **o) {
    *ivar = value;
}
static NSString *_logProcessPrefix = 0;
void func(void) {
  __setRetained(&_logProcessPrefix, _logProcessPrefix, &_logProcessPrefix);
}
@implementation NSObject (ScopeAdditions)
+ (void)setObjectLogProcessPrefix:(NSString *)processPrefix {
    __setRetained(&_logProcessPrefix, processPrefix, &_logProcessPrefix);
}
@end

@class Derived;

NSObject *ExternFunc (NSObject *filePath, NSObject *key);
typedef id FuncSignature (NSObject *arg1, Derived *arg2);

@interface Derived: NSObject
+ (void)registerFunc:(FuncSignature *)function; // expected-note{{passing argument to parameter 'function' here}}
@end

void foo(void)
{
  // GCC currently allows this (it has some fairly new support for covariant return types and contravariant argument types).
  // Since registerFunc: expects a Derived object as it's second argument, I don't know why this would be legal.
  [Derived registerFunc: ExternFunc];  // expected-error{{incompatible function pointer types sending 'NSObject *(NSObject *, NSObject *)' to parameter of type 'FuncSignature *' (aka 'id (*)(NSObject *, Derived *)')}}
}

// rdar://10751015
@protocol NSCopying @end
@interface I
- (void) Meth : (id <NSCopying>)aKey; // expected-note {{passing argument to parameter 'aKey' here}}
@end

@class ForwarClass; // expected-note 3 {{conformance of forward class 'ForwarClass' to protocol 'NSCopying' can not be confirmed}}

ForwarClass *Test10751015 (I* pi, ForwarClass *ns_forward) {

  [pi Meth : ns_forward ]; // expected-warning {{sending 'ForwarClass *' to parameter of incompatible type 'id<NSCopying>'}}

  id <NSCopying> id_ns = ns_forward; // expected-warning {{initializing 'id<NSCopying>' with an expression of incompatible type 'ForwarClass *'}}

  return id_ns; // expected-warning {{returning 'id<NSCopying>' from a function with incompatible result type 'ForwarClass *'}}
}