[cfe-commits] r117354 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaObjCXX/overload.mm
John McCall
rjmccall at apple.com
Mon Oct 25 23:23:29 PDT 2010
Author: rjmccall
Date: Tue Oct 26 01:23:29 2010
New Revision: 117354
URL: http://llvm.org/viewvc/llvm-project?rev=117354&view=rev
Log:
Consider conversions of Objective-C pointers to 'id' to be basically of
the same rank as conversions of normal pointers to 'void*'.
Also, resurrect a test case.
Fixes rdar://problem/8592139
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaObjCXX/overload.mm
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=117354&r1=117353&r2=117354&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Oct 26 01:23:29 2010
@@ -200,6 +200,9 @@
/// conversion is a conversion of a pointer to a void pointer. This is
/// used as part of the ranking of standard conversion sequences (C++
/// 13.3.3.2p4).
+///
+/// Note that we treat conversions of Objective-C pointers to
+/// unqualified 'id' as having this same rank.
bool
StandardConversionSequence::
isPointerConversionToVoidPointer(ASTContext& Context) const {
@@ -212,9 +215,15 @@
if (First == ICK_Array_To_Pointer)
FromType = Context.getArrayDecayedType(FromType);
- if (Second == ICK_Pointer_Conversion && FromType->isPointerType())
+ if (Second == ICK_Pointer_Conversion && FromType->isPointerType()) {
if (const PointerType* ToPtrType = ToType->getAs<PointerType>())
return ToPtrType->getPointeeType()->isVoidType();
+ } else if (Second == ICK_Pointer_Conversion &&
+ FromType->isObjCObjectPointerType()) {
+ if (const ObjCObjectPointerType *ToPtrType =
+ ToType->getAs<ObjCObjectPointerType>())
+ return ToPtrType->isObjCIdType();
+ }
return false;
}
Modified: cfe/trunk/test/SemaObjCXX/overload.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/overload.mm?rev=117354&r1=117353&r2=117354&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/overload.mm (original)
+++ cfe/trunk/test/SemaObjCXX/overload.mm Tue Oct 26 01:23:29 2010
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-// XFAIL: *
@interface Foo
@end
@@ -28,17 +27,20 @@
@interface C <P1>
@end
-int& f(A*);
-float& f(B*);
+int& f(A*); // expected-note {{candidate}}
+float& f(B*); // expected-note {{candidate}}
void g(A*);
int& h(A*);
float& h(id);
-void test(A* a, B* b, id val) {
+void test0(A* a, B* b, id val) {
int& i1 = f(a);
float& f1 = f(b);
- float& f2 = f(val);
+
+ // GCC succeeds here, which is clearly ridiculous.
+ float& f2 = f(val); // expected-error {{ambiguous}}
+
g(a);
g(b);
g(val);
@@ -47,36 +49,45 @@
// int& i3 = h(b); FIXME: we match GCC here, but shouldn't this work?
}
-void downcast_test(A* a, A** ap) {
- B* b = a; // expected-warning{{incompatible pointer types initializing 'B *', expected 'A *'}}
- b = a; // expected-warning{{incompatible pointer types assigning 'B *', expected 'A *'}}
-
- B** bp = ap; // expected-warning{{incompatible pointer types initializing 'B **', expected 'A **'}}
- bp = ap; // expected-warning{{incompatible pointer types assigning 'B **', expected 'A **'}}
+// We make these errors instead of warnings. Is that okay?
+void test1(A* a) {
+ B* b = a; // expected-error{{cannot initialize a variable of type 'B *' with an lvalue of type 'A *'}}
+ B *c; c = a; // expected-error{{assigning to 'B *' from incompatible type 'A *'}}
+}
+
+void test2(A** ap) {
+ B** bp = ap; // expected-warning{{incompatible pointer types converting 'A **' to type 'B **'}}
+ bp = ap; // expected-warning{{incompatible pointer types assigning to 'A **' from 'B **'}}
}
-int& cv(A*);
-float& cv(const A*);
-int& cv2(void*);
-float& cv2(const void*);
+// 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}}
+
+int& cv2(void*); // expected-note 2 {{candidate}}
+float& cv2(const void*); // expected-note 2 {{candidate}}
void cv_test(A* a, B* b, const A* ac, const B* bc) {
int &i1 = cv(a);
int &i2 = cv(b);
- float &f1 = cv(ac);
- float &f2 = cv(bc);
- int& i3 = cv2(a);
- float& f3 = cv2(ac);
-}
+ float &f1 = cv(ac); // expected-error {{no matching function}}
+ float &f2 = cv(bc); // expected-error {{no matching function}}
+ // FIXME: these should not be ambiguous
+ int& i3 = cv2(a); // expected-error {{ambiguous}}
+ float& f3 = cv2(ac); // expected-error {{ambiguous}}
+}
-int& qualid(id<P0>);
-float& qualid(id<P1>); // FIXME: GCC complains that this isn't an overload. Is it?
+// 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}}
void qualid_test(A *a, B *b, C *c) {
int& i1 = qualid(a);
int& i2 = qualid(b);
- float& f1 = qualid(c);
+
+ // This doesn't work only because the overload was rejected above.
+ float& f1 = qualid(c); // expected-error {{no matching function}}
id<P0> p1 = 0;
p1 = 0;
@@ -91,7 +102,7 @@
void (*_NSExceptionRaiser(void))(NSException *) {
objc_exception_functions_t exc_funcs;
- return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(NSException *)', expected 'void (*)(id)'}}
+ return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types converting 'void (*)(id)' to type 'void (*)(NSException *)'}}
}
namespace test5 {
@@ -102,3 +113,13 @@
foo(p);
}
}
+
+// rdar://problem/8592139
+namespace test6 {
+ void foo(id); // expected-note {{candidate}}
+ void foo(A*) __attribute__((unavailable)); // expected-note {{explicitly made unavailable}}
+
+ void test(B *b) {
+ foo(b); // expected-error {{call to unavailable function}}
+ }
+}
More information about the cfe-commits
mailing list