blob: 47a9d07d41c2953b93973edba58e903b19b0e635 [file] [log] [blame]
Douglas Gregor4b60a152013-11-07 22:34:54 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s -verify
2
3@interface A
4- knownMethod;
5@end
6
7@interface B
8- unknownMethod;
9@end
10
Douglas Gregor68782142013-12-18 21:46:16 +000011@interface C : A
12- knownMethod;
13@end
14
Douglas Gregor4b60a152013-11-07 22:34:54 +000015template<typename T> struct RetainPtr {
16 explicit operator T*() const;
17};
18
19void methodCallToSpecific(RetainPtr<A> a) {
20 [a knownMethod];
21 [a unknownMethod]; // expected-warning{{'A' may not respond to 'unknownMethod'}}
22}
23
Douglas Gregor68782142013-12-18 21:46:16 +000024void explicitCast(RetainPtr<A> a, RetainPtr<B> b, RetainPtr<C> c) {
25 (void)(A*)a;
26 (void)(A*)b; // expected-error{{cannot convert 'RetainPtr<B>' to 'A *' without a conversion operator}}
27 (void)(A*)c;
28 (void)(C*)a;
29 (void)static_cast<A*>(a);
30 (void)static_cast<A*>(b); // expected-error{{cannot convert 'RetainPtr<B>' to 'A *' without a conversion operator}}
31 (void)static_cast<A*>(c);
32}
33
Douglas Gregor4b60a152013-11-07 22:34:54 +000034struct Incomplete; // expected-note{{forward declaration}}
35
36void methodCallToIncomplete(Incomplete &incomplete) {
37 [incomplete knownMethod]; // expected-error{{incomplete receiver type 'Incomplete'}}
38}
39
40struct IdPtr {
41 explicit operator id() const;
42};
43
44void methodCallToId(IdPtr a) {
45 [a knownMethod];
46 [a unknownMethod];
47}
Douglas Gregor68782142013-12-18 21:46:16 +000048
49void explicitCast(IdPtr a) {
50 (void)(A*)a;
51 (void)static_cast<A*>(a);
52}