annotate clang/test/SemaObjC/conditional-expr-4.m @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2 // <rdar://problem/6212771>
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 #define nil ((void*) 0)
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 @interface A
anatofuz
parents:
diff changeset
7 @property int x;
anatofuz
parents:
diff changeset
8 @end
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 @interface B : A
anatofuz
parents:
diff changeset
11 @end
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 // Basic checks...
anatofuz
parents:
diff changeset
14 id f0(int cond, id a, void *b) {
anatofuz
parents:
diff changeset
15 return cond ? a : b;
anatofuz
parents:
diff changeset
16 }
anatofuz
parents:
diff changeset
17 A *f0_a(int cond, A *a, void *b) {
anatofuz
parents:
diff changeset
18 return cond ? a : b;
anatofuz
parents:
diff changeset
19 }
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 id f1(int cond, id a) {
anatofuz
parents:
diff changeset
22 return cond ? a : nil;
anatofuz
parents:
diff changeset
23 }
anatofuz
parents:
diff changeset
24 A *f1_a(int cond, A *a) {
anatofuz
parents:
diff changeset
25 return cond ? a : nil;
anatofuz
parents:
diff changeset
26 }
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 void *f1_const_a(int x, void *p, const A * q) {
anatofuz
parents:
diff changeset
29 void *r = x ? p : q; // expected-warning{{initializing 'void *' with an expression of type 'const void *' discards qualifiers}}
anatofuz
parents:
diff changeset
30 return r;
anatofuz
parents:
diff changeset
31 }
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 // Check interaction with qualified id
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 @protocol P0 @end
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 id f2(int cond, id<P0> a, void *b) {
anatofuz
parents:
diff changeset
38 return cond ? a : b;
anatofuz
parents:
diff changeset
39 }
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 id f3(int cond, id<P0> a) {
anatofuz
parents:
diff changeset
42 return cond ? a : nil;
anatofuz
parents:
diff changeset
43 }
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 // Check that result actually has correct type.
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 // Using properties is one way to find the compiler internal type of a
anatofuz
parents:
diff changeset
48 // conditional expression. Simple assignment doesn't work because if
anatofuz
parents:
diff changeset
49 // the type is id then it can be implicitly promoted.
anatofuz
parents:
diff changeset
50 @protocol P1
anatofuz
parents:
diff changeset
51 @property int x;
anatofuz
parents:
diff changeset
52 @end
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 int f5(int cond, id<P1> a, id<P1> b) {
anatofuz
parents:
diff changeset
55 return (cond ? a : b).x;
anatofuz
parents:
diff changeset
56 }
anatofuz
parents:
diff changeset
57 int f5_a(int cond, A *a, A *b) {
anatofuz
parents:
diff changeset
58 return (cond ? a : b).x;
anatofuz
parents:
diff changeset
59 }
anatofuz
parents:
diff changeset
60 int f5_b(int cond, A *a, B *b) {
anatofuz
parents:
diff changeset
61 return (cond ? a : b).x;
anatofuz
parents:
diff changeset
62 }
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 int f6(int cond, id<P1> a, void *b) {
anatofuz
parents:
diff changeset
65 // This should result in something with id type, currently.
anatofuz
parents:
diff changeset
66 return (cond ? a : b).x; // expected-error {{member reference base type 'void *' is not a structure or union}}
anatofuz
parents:
diff changeset
67 }
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69 int f7(int cond, id<P1> a) {
anatofuz
parents:
diff changeset
70 return (cond ? a : nil).x;
anatofuz
parents:
diff changeset
71 }
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 int f8(int cond, id<P1> a, A *b) {
anatofuz
parents:
diff changeset
74 return a == b; // expected-warning {{comparison of distinct pointer types ('id<P1>' and 'A *')}}
anatofuz
parents:
diff changeset
75 }
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 int f9(int cond, id<P1> a, A *b) {
anatofuz
parents:
diff changeset
78 return (cond ? a : b).x; // expected-warning {{incompatible operand types ('id<P1>' and 'A *')}} \
anatofuz
parents:
diff changeset
79 expected-error {{property 'x' not found on object of type 'id'}}
anatofuz
parents:
diff changeset
80 }