summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaObjC
diff options
context:
space:
mode:
authorJames Y Knight <jyknight@google.com>2019-10-17 15:27:04 +0000
committerJames Y Knight <jyknight@google.com>2019-10-17 15:27:04 +0000
commitccc4d83cda16bea1d9dfd0967dc7d2cfb24b8e75 (patch)
tree7730dd616da7b04af72b36b95cd7c7e4c9311ad0 /clang/test/SemaObjC
parent1c982af0599781bdb049f898a2d512656c807485 (diff)
downloadbcm5719-llvm-ccc4d83cda16bea1d9dfd0967dc7d2cfb24b8e75.tar.gz
bcm5719-llvm-ccc4d83cda16bea1d9dfd0967dc7d2cfb24b8e75.zip
[ObjC] Diagnose implicit type coercion from ObjC 'Class' to object
pointer types. For example, in Objective-C mode, the initialization of 'x' in: ``` @implementation MyType + (void)someClassMethod { MyType *x = self; } @end ``` is correctly diagnosed with an incompatible-pointer-types warning, but in Objective-C++ mode, it is not diagnosed at all -- even though incompatible pointer conversions generally become an error in C++. This patch fixes that oversight, allowing implicit conversions involving Class only to/from unqualified-id, and between qualified and unqualified Class, where the protocols are compatible. Note that this does change some behaviors in Objective-C, as well, as shown by the modified tests. Of particular note is that assignment from from 'Class<MyProtocol>' to 'id<MyProtocol>' now warns. (Despite appearances, those are not compatible types. 'Class<MyProtocol>' is not expected to have instance methods defined by 'MyProtocol', while 'id<MyProtocol>' is.) Differential Revision: https://reviews.llvm.org/D67983 llvm-svn: 375125
Diffstat (limited to 'clang/test/SemaObjC')
-rw-r--r--clang/test/SemaObjC/comptypes-1.m18
1 files changed, 9 insertions, 9 deletions
diff --git a/clang/test/SemaObjC/comptypes-1.m b/clang/test/SemaObjC/comptypes-1.m
index 9b62f974927..67b73ce0f8a 100644
--- a/clang/test/SemaObjC/comptypes-1.m
+++ b/clang/test/SemaObjC/comptypes-1.m
@@ -49,7 +49,7 @@ int main()
obj_p = obj_c; // expected-warning {{assigning to 'id<MyProtocol>' from incompatible type 'MyClass *'}}
obj_p = obj_cp; /* Ok */
obj_p = obj_C; // expected-warning {{incompatible pointer types assigning to 'id<MyProtocol>' from 'Class'}}
- obj_p = obj_CP; // FIXME -- should warn {{assigning to 'id<MyProtocol>' from incompatible type 'Class<MyProtocol>'}}
+ obj_p = obj_CP; // expected-warning {{assigning to 'id<MyProtocol>' from incompatible type 'Class<MyProtocol>'}}
/* Assigning to a 'MyOtherClass *' variable should always generate
a warning, unless done from an 'id' or an 'id<MyProtocol>' (since
@@ -92,8 +92,8 @@ int main()
if (obj_c == obj_cp) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}}
if (obj_cp == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}}
- if (obj_c == obj_C) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('MyClass *' and 'Class')}}
- if (obj_C == obj_c) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'MyClass *')}}
+ if (obj_c == obj_C) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'Class')}}
+ if (obj_C == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('Class' and 'MyClass *')}}
if (obj_c == obj_CP) foo(); // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'Class<MyProtocol>')}}
if (obj_CP == obj_c) foo(); // expected-warning {{comparison of distinct pointer types ('Class<MyProtocol>' and 'MyClass *')}}
@@ -103,15 +103,15 @@ int main()
if (obj_p == obj_cp) foo(); /* Ok */
if (obj_cp == obj_p) foo(); /* Ok */
- if (obj_p == obj_C) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class')}}
- if (obj_C == obj_p) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'id<MyProtocol>')}}
+ if (obj_p == obj_C) foo(); // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class')}}
+ if (obj_C == obj_p) foo(); // expected-warning {{comparison of distinct pointer types ('Class' and 'id<MyProtocol>')}}
- if (obj_p == obj_CP) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class<MyProtocol>')}}
- if (obj_CP == obj_p) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('Class<MyProtocol>' and 'id<MyProtocol>')}}
+ if (obj_p == obj_CP) foo(); // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'Class<MyProtocol>')}}
+ if (obj_CP == obj_p) foo(); // expected-warning {{comparison of distinct pointer types ('Class<MyProtocol>' and 'id<MyProtocol>')}}
/* Comparisons between MyOtherClass * and Class types is a warning */
- if (obj_cp == obj_C) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('MyOtherClass *' and 'Class')}}
- if (obj_C == obj_cp) foo(); // FIXME -- should warn {{comparison of distinct pointer types ('Class' and 'MyOtherClass *')}}
+ if (obj_cp == obj_C) foo(); // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'Class')}}
+ if (obj_C == obj_cp) foo(); // expected-warning {{comparison of distinct pointer types ('Class' and 'MyOtherClass *')}}
if (obj_cp == obj_CP) foo(); // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'Class<MyProtocol>')}}
if (obj_CP == obj_cp) foo(); // expected-warning {{comparison of distinct pointer types ('Class<MyProtocol>' and 'MyOtherClass *')}}
OpenPOWER on IntegriCloud