2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify %s
2008-12-19 07:43:31 +08:00
@interface Foo
@end
@implementation Foo
void func(id);
+ zone {
func(self);
return self;
}
2008-12-20 03:16:37 +08:00
@end
2008-12-19 07:43:31 +08:00
2008-11-27 09:19:21 +08:00
@protocol P0
@end
@protocol P1
@end
@interface A <P0>
2008-11-27 07:31:11 +08:00
@end
@interface B : A
@end
2008-11-27 09:19:21 +08:00
@interface C <P1>
@end
2010-10-26 14:23:29 +08:00
int& f(A*); // expected-note {{candidate}}
float& f(B*); // expected-note {{candidate}}
2008-11-27 07:31:11 +08:00
void g(A*);
Implement reasonable conversion ranking for Objective-C pointer
conversions (<rdar://problem/8592139>) for overload resolution. The
conversion ranking mirrors C++'s conversion ranking fairly closely,
except that we use a same pseudo-subtyping relationship employed by
Objective-C pointer assignment rather than simple checking
derived-to-base conversions. This change covers:
- Conversions to pointers to a specific object type are better than
conversions to 'id', 'Class', qualified 'id', or qualified 'Class'
(note: GCC doesn't perform this ranking, but it matches C++'s rules
for ranking conversions to void*).
- Conversions to qualified 'id' or qualified 'Class' are better than
conversions to 'id' or 'Class', respectively.
- When two conversion sequences convert to the same type, rank the
conversions based on the relationship between the types we're
converting from.
- When two conversion sequences convert from the same non-id,
non-Class type, rank the conversions based on the relationship of
the types we're converting to. (note: GCC allows this ranking even
when converting from 'id', which is extremeley dangerous).
llvm-svn: 124591
2011-02-01 02:51:41 +08:00
int& h(A*);
float& h(id);
2008-11-27 07:31:11 +08:00
2010-10-26 14:23:29 +08:00
void test0(A* a, B* b, id val) {
2008-11-27 07:31:11 +08:00
int& i1 = f(a);
float& f1 = f(b);
2010-10-26 14:23:29 +08:00
// GCC succeeds here, which is clearly ridiculous.
float& f2 = f(val); // expected-error {{ambiguous}}
2008-11-27 07:31:11 +08:00
g(a);
g(b);
g(val);
int& i2 = h(a);
float& f3 = h(val);
2010-12-02 05:43:58 +08:00
Implement reasonable conversion ranking for Objective-C pointer
conversions (<rdar://problem/8592139>) for overload resolution. The
conversion ranking mirrors C++'s conversion ranking fairly closely,
except that we use a same pseudo-subtyping relationship employed by
Objective-C pointer assignment rather than simple checking
derived-to-base conversions. This change covers:
- Conversions to pointers to a specific object type are better than
conversions to 'id', 'Class', qualified 'id', or qualified 'Class'
(note: GCC doesn't perform this ranking, but it matches C++'s rules
for ranking conversions to void*).
- Conversions to qualified 'id' or qualified 'Class' are better than
conversions to 'id' or 'Class', respectively.
- When two conversion sequences convert to the same type, rank the
conversions based on the relationship between the types we're
converting from.
- When two conversion sequences convert from the same non-id,
non-Class type, rank the conversions based on the relationship of
the types we're converting to. (note: GCC allows this ranking even
when converting from 'id', which is extremeley dangerous).
llvm-svn: 124591
2011-02-01 02:51:41 +08:00
int& i3 = h(b);
2008-11-27 07:31:11 +08:00
}
2010-10-26 14:23:29 +08:00
void test1(A* a) {
2011-03-22 03:08:42 +08:00
B* b = a; // expected-warning{{incompatible pointer types initializing 'B *' with an expression of type 'A *'}}
2011-06-11 12:42:12 +08:00
B *c; c = a; // expected-warning{{incompatible pointer types assigning to 'B *' from 'A *'}}
2010-10-26 14:23:29 +08:00
}
2008-12-20 03:13:09 +08:00
2010-10-26 14:23:29 +08:00
void test2(A** ap) {
2011-03-22 03:08:42 +08:00
B** bp = ap; // expected-warning{{incompatible pointer types initializing 'B **' with an expression of type 'A **'}}
2011-06-11 12:42:12 +08:00
bp = ap; // expected-warning{{incompatible pointer types assigning to 'B **' from 'A **'}}
2008-12-20 01:40:08 +08:00
}
2010-10-26 14:23:29 +08:00
// FIXME: we should either allow overloading here or give a better diagnostic
int& cv(A*); // expected-note {{previous declaration}} expected-note 2 {{not viable}}
float& cv(const A*); // expected-error {{cannot be overloaded}}
2010-12-02 05:43:58 +08:00
int& cv2(void*);
float& cv2(const void*);
2008-11-27 07:31:11 +08:00
void cv_test(A* a, B* b, const A* ac, const B* bc) {
int &i1 = cv(a);
int &i2 = cv(b);
2010-10-26 14:23:29 +08:00
float &f1 = cv(ac); // expected-error {{no matching function}}
float &f2 = cv(bc); // expected-error {{no matching function}}
2010-12-02 05:43:58 +08:00
int& i3 = cv2(a);
float& f3 = cv2(ac);
2010-10-26 14:23:29 +08:00
}
2008-11-27 09:19:21 +08:00
2010-10-26 14:23:29 +08:00
// We agree with GCC that these can't be overloaded.
int& qualid(id<P0>); // expected-note {{previous declaration}} expected-note {{not viable}}
float& qualid(id<P1>); // expected-error {{cannot be overloaded}}
2008-11-27 09:19:21 +08:00
void qualid_test(A *a, B *b, C *c) {
int& i1 = qualid(a);
int& i2 = qualid(b);
2010-10-26 14:23:29 +08:00
// This doesn't work only because the overload was rejected above.
float& f1 = qualid(c); // expected-error {{no matching function}}
2008-12-23 04:51:52 +08:00
id<P0> p1 = 0;
p1 = 0;
2008-11-27 09:19:21 +08:00
}
2008-12-20 03:13:09 +08:00
@class NSException;
typedef struct {
void (*throw_exc)(id);
}
objc_exception_functions_t;
void (*_NSExceptionRaiser(void))(NSException *) {
objc_exception_functions_t exc_funcs;
2010-12-03 05:47:04 +08:00
return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(id)' from a function with result type 'void (*)(NSException *)'}}
2008-12-20 03:13:09 +08:00
}
2010-06-11 18:04:22 +08:00
namespace test5 {
void foo(bool);
void foo(void *);
void test(id p) {
foo(p);
}
}
2010-10-26 14:23:29 +08:00
// rdar://problem/8592139
namespace test6 {
Implement reasonable conversion ranking for Objective-C pointer
conversions (<rdar://problem/8592139>) for overload resolution. The
conversion ranking mirrors C++'s conversion ranking fairly closely,
except that we use a same pseudo-subtyping relationship employed by
Objective-C pointer assignment rather than simple checking
derived-to-base conversions. This change covers:
- Conversions to pointers to a specific object type are better than
conversions to 'id', 'Class', qualified 'id', or qualified 'Class'
(note: GCC doesn't perform this ranking, but it matches C++'s rules
for ranking conversions to void*).
- Conversions to qualified 'id' or qualified 'Class' are better than
conversions to 'id' or 'Class', respectively.
- When two conversion sequences convert to the same type, rank the
conversions based on the relationship between the types we're
converting from.
- When two conversion sequences convert from the same non-id,
non-Class type, rank the conversions based on the relationship of
the types we're converting to. (note: GCC allows this ranking even
when converting from 'id', which is extremeley dangerous).
llvm-svn: 124591
2011-02-01 02:51:41 +08:00
void foo(id); // expected-note{{candidate function}}
2010-10-26 14:23:29 +08:00
void foo(A*) __attribute__((unavailable)); // expected-note {{explicitly made unavailable}}
void test(B *b) {
Implement reasonable conversion ranking for Objective-C pointer
conversions (<rdar://problem/8592139>) for overload resolution. The
conversion ranking mirrors C++'s conversion ranking fairly closely,
except that we use a same pseudo-subtyping relationship employed by
Objective-C pointer assignment rather than simple checking
derived-to-base conversions. This change covers:
- Conversions to pointers to a specific object type are better than
conversions to 'id', 'Class', qualified 'id', or qualified 'Class'
(note: GCC doesn't perform this ranking, but it matches C++'s rules
for ranking conversions to void*).
- Conversions to qualified 'id' or qualified 'Class' are better than
conversions to 'id' or 'Class', respectively.
- When two conversion sequences convert to the same type, rank the
conversions based on the relationship between the types we're
converting from.
- When two conversion sequences convert from the same non-id,
non-Class type, rank the conversions based on the relationship of
the types we're converting to. (note: GCC allows this ranking even
when converting from 'id', which is extremeley dangerous).
llvm-svn: 124591
2011-02-01 02:51:41 +08:00
foo(b); // expected-error {{call to unavailable function 'foo'}}
2010-10-26 14:23:29 +08:00
}
}
2010-12-02 05:43:58 +08:00
namespace rdar8714395 {
int &f(const void*);
float &f(const Foo*);
int &f2(const void*);
float &f2(Foo const* const *);
int &f3(const void*);
float &f3(Foo const**);
void g(Foo *p) {
float &fr = f(p);
float &fr2 = f2(&p);
int &ir = f3(&p);
}
}
2010-12-07 06:09:19 +08:00
namespace rdar8734046 {
void f1(id);
void f2(id<P0>);
void g(const A *a) {
f1(a);
f2(a);
}
}
2011-04-16 04:45:44 +08:00
namespace PR9735 {
int &f3(const A*);
float &f3(const void*);
void test_f(B* b, const B* bc) {
int &ir1 = f3(b);
int &ir2 = f3(bc);
}
}
2011-04-27 08:01:52 +08:00
@interface D : B
@end
namespace rdar9327203 {
int &f(void* const&, int);
float &f(void* const&, long);
void g(id x) {
int &fr = (f)(x, 0);
}
}