• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1  -fsyntax-only -triple x86_64-apple-macosx10.9 -verify %s
2
3#define BOXABLE __attribute__((objc_boxable))
4
5typedef struct BOXABLE _NSPoint {
6  int dummy;
7} NSPoint;
8
9typedef struct BOXABLE _NSSize {
10  int dummy;
11} NSSize;
12
13typedef struct BOXABLE _NSRect {
14  int dummy;
15} NSRect;
16
17typedef struct BOXABLE _CGPoint {
18  int dummy;
19} CGPoint;
20
21typedef struct BOXABLE _CGSize {
22  int dummy;
23} CGSize;
24
25typedef struct BOXABLE _CGRect {
26  int dummy;
27} CGRect;
28
29typedef struct BOXABLE _NSRange {
30  int dummy;
31} NSRange;
32
33struct _NSEdgeInsets {
34  int dummy;
35};
36
37typedef struct BOXABLE _NSEdgeInsets NSEdgeInsets;
38
39typedef struct _SomeStruct {
40  double d;
41} SomeStruct;
42
43typedef union BOXABLE _BoxableUnion {
44  int dummy;
45} BoxableUnion;
46
47void checkNSValueDiagnostic() {
48  NSRect rect;
49  id value = @(rect); // expected-error{{definition of class NSValue must be available to use Objective-C boxed expressions}}
50}
51
52@interface NSValue
53+ (NSValue *)valueWithBytes:(const void *)value objCType:(const char *)type;
54@end
55
56int main() {
57  NSPoint ns_point;
58  id ns_point_value = @(ns_point);
59
60  NSSize ns_size;
61  id ns_size_value = @(ns_size);
62
63  NSRect ns_rect;
64  id ns_rect_value = @(ns_rect);
65
66  CGPoint cg_point;
67  id cg_point_value = @(cg_point);
68
69  CGSize cg_size;
70  id cg_size_value = @(cg_size);
71
72  CGRect cg_rect;
73  id cg_rect_value = @(cg_rect);
74
75  NSRange ns_range;
76  id ns_range_value = @(ns_range);
77
78  NSEdgeInsets edge_insets;
79  id edge_insets_object = @(edge_insets);
80
81  BoxableUnion boxable_union;
82  id boxed_union = @(boxable_union);
83
84  SomeStruct s;
85  id err = @(s); // expected-error{{illegal type 'SomeStruct' (aka 'struct _SomeStruct') used in a boxed expression}}
86}
87
88CGRect getRect() {
89  CGRect r;
90  return r;
91}
92
93SomeStruct getSomeStruct() {
94  SomeStruct s;
95  return s;
96}
97
98void rvalue() {
99  id rv_rect = @(getRect());
100  id rv_some_struct = @(getSomeStruct()); // expected-error {{illegal type 'SomeStruct' (aka 'struct _SomeStruct') used in a boxed expression}}
101}
102