1 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9 -verify %s
3 #define BOXABLE __attribute__((objc_boxable))
5 typedef struct BOXABLE _NSPoint {
9 typedef struct BOXABLE _NSSize {
13 typedef struct BOXABLE _NSRect {
17 typedef struct BOXABLE _CGPoint {
21 typedef struct BOXABLE _CGSize {
25 typedef struct BOXABLE _CGRect {
29 typedef struct BOXABLE _NSRange {
33 typedef struct BOXABLE _NSEdgeInsets {
37 typedef struct BOXABLE _NSEdgeInsets NSEdgeInsets;
39 typedef struct _SomeStruct {
43 struct BOXABLE NonTriviallyCopyable {
45 NonTriviallyCopyable() {}
46 NonTriviallyCopyable(const NonTriviallyCopyable &obj) {}
49 void checkNSValueDiagnostic() {
51 id value = @(rect); // expected-error{{definition of class NSValue must be available to use Objective-C boxed expressions}}
55 + (NSValue *)valueWithBytes:(const void *)value objCType:(const char *)type;
60 id ns_point_value = @(ns_point);
63 id ns_size_value = @(ns_size);
66 id ns_rect_value = @(ns_rect);
69 id cg_point_value = @(cg_point);
72 id cg_size_value = @(cg_size);
75 id cg_rect_value = @(cg_rect);
78 id ns_range_value = @(ns_range);
80 NSEdgeInsets edge_insets;
81 id edge_insets_object = @(edge_insets);
84 id err = @(s); // expected-error{{illegal type 'SomeStruct' (aka '_SomeStruct') used in a boxed expression}}
86 NonTriviallyCopyable ntc;
87 id ntcErr = @(ntc); // expected-error{{non-trivially copyable type 'NonTriviallyCopyable' cannot be used in a boxed expression}}
95 SomeStruct getSomeStruct() {
101 id rv_rect = @(getRect());
102 id rv_some_struct = @(getSomeStruct()); // expected-error {{illegal type 'SomeStruct' (aka '_SomeStruct') used in a boxed expression}}
105 template <class T> id box(T value) { return @(value); } // expected-error{{non-trivially copyable type 'NonTriviallyCopyable' cannot be used in a boxed expression}}
106 void test_template_1(NSRect rect, NonTriviallyCopyable ntc) {
108 id y = box(ntc); // expected-note{{in instantiation of function template specialization 'box<NonTriviallyCopyable>' requested here}}
111 template <unsigned i> id boxRect(NSRect rect) { return @(rect); }
112 template <unsigned i> id boxNTC(NonTriviallyCopyable ntc) { return @(ntc); } // expected-error{{non-trivially copyable type 'NonTriviallyCopyable' cannot be used in a boxed expression}}
113 void test_template_2(NSRect rect, NonTriviallyCopyable ntc) {
114 id x = boxRect<0>(rect);
115 id y = boxNTC<0>(ntc);