| 1 |
// RUN: %clang_cc1 -fsyntax-only -fobjc-weak -fobjc-runtime-has-weak -verify -std=c++11 %s -Wno-deprecated-builtins |
| 2 |
|
| 3 |
// Check the results of the various type-trait query functions on |
| 4 |
// lifetime-qualified types in ObjC Weak. |
| 5 |
|
| 6 |
#define TRAIT_IS_TRUE(Trait, Type) static_assert(Trait(Type), "") |
| 7 |
#define TRAIT_IS_FALSE(Trait, Type) static_assert(!Trait(Type), "") |
| 8 |
#define TRAIT_IS_TRUE_2(Trait, Type1, Type2) static_assert(Trait(Type1, Type2), "") |
| 9 |
#define TRAIT_IS_FALSE_2(Trait, Type1, Type2) static_assert(!Trait(Type1, Type2), "") |
| 10 |
|
| 11 |
struct HasStrong { id obj; }; |
| 12 |
struct HasWeak { __weak id obj; }; |
| 13 |
struct HasUnsafeUnretained { __unsafe_unretained id obj; }; |
| 14 |
|
| 15 |
// __has_nothrow_assign |
| 16 |
TRAIT_IS_TRUE(__has_nothrow_assign, __strong id); |
| 17 |
TRAIT_IS_TRUE(__has_nothrow_assign, __weak id); |
| 18 |
TRAIT_IS_TRUE(__has_nothrow_assign, __autoreleasing id); |
| 19 |
TRAIT_IS_TRUE(__has_nothrow_assign, __unsafe_unretained id); |
| 20 |
TRAIT_IS_TRUE(__has_nothrow_assign, HasStrong); |
| 21 |
TRAIT_IS_TRUE(__has_nothrow_assign, HasWeak); |
| 22 |
TRAIT_IS_TRUE(__has_nothrow_assign, HasUnsafeUnretained); |
| 23 |
|
| 24 |
// __has_nothrow_copy |
| 25 |
TRAIT_IS_TRUE(__has_nothrow_copy, __strong id); |
| 26 |
TRAIT_IS_TRUE(__has_nothrow_copy, __weak id); |
| 27 |
TRAIT_IS_TRUE(__has_nothrow_copy, __autoreleasing id); |
| 28 |
TRAIT_IS_TRUE(__has_nothrow_copy, __unsafe_unretained id); |
| 29 |
TRAIT_IS_TRUE(__has_nothrow_copy, HasStrong); |
| 30 |
TRAIT_IS_TRUE(__has_nothrow_copy, HasWeak); |
| 31 |
TRAIT_IS_TRUE(__has_nothrow_copy, HasUnsafeUnretained); |
| 32 |
|
| 33 |
// __has_nothrow_constructor |
| 34 |
TRAIT_IS_TRUE(__has_nothrow_constructor, __strong id); |
| 35 |
TRAIT_IS_TRUE(__has_nothrow_constructor, __weak id); |
| 36 |
TRAIT_IS_TRUE(__has_nothrow_constructor, __autoreleasing id); |
| 37 |
TRAIT_IS_TRUE(__has_nothrow_constructor, __unsafe_unretained id); |
| 38 |
TRAIT_IS_TRUE(__has_nothrow_constructor, HasStrong); |
| 39 |
TRAIT_IS_TRUE(__has_nothrow_constructor, HasWeak); |
| 40 |
TRAIT_IS_TRUE(__has_nothrow_constructor, HasUnsafeUnretained); |
| 41 |
|
| 42 |
// __has_trivial_assign |
| 43 |
TRAIT_IS_TRUE(__has_trivial_assign, __strong id); |
| 44 |
TRAIT_IS_FALSE(__has_trivial_assign, __weak id); |
| 45 |
TRAIT_IS_TRUE(__has_trivial_assign, __autoreleasing id); |
| 46 |
TRAIT_IS_TRUE(__has_trivial_assign, __unsafe_unretained id); |
| 47 |
TRAIT_IS_TRUE(__has_trivial_assign, HasStrong); |
| 48 |
TRAIT_IS_FALSE(__has_trivial_assign, HasWeak); |
| 49 |
TRAIT_IS_TRUE(__has_trivial_assign, HasUnsafeUnretained); |
| 50 |
|
| 51 |
// __has_trivial_copy |
| 52 |
TRAIT_IS_TRUE(__has_trivial_copy, __strong id); |
| 53 |
TRAIT_IS_FALSE(__has_trivial_copy, __weak id); |
| 54 |
TRAIT_IS_TRUE(__has_trivial_copy, __autoreleasing id); |
| 55 |
TRAIT_IS_TRUE(__has_trivial_copy, __unsafe_unretained id); |
| 56 |
TRAIT_IS_TRUE(__has_trivial_copy, HasStrong); |
| 57 |
TRAIT_IS_FALSE(__has_trivial_copy, HasWeak); |
| 58 |
TRAIT_IS_TRUE(__has_trivial_copy, HasUnsafeUnretained); |
| 59 |
|
| 60 |
// __has_trivial_constructor |
| 61 |
TRAIT_IS_TRUE(__has_trivial_constructor, __strong id); |
| 62 |
TRAIT_IS_FALSE(__has_trivial_constructor, __weak id); |
| 63 |
TRAIT_IS_TRUE(__has_trivial_constructor, __autoreleasing id); |
| 64 |
TRAIT_IS_TRUE(__has_trivial_constructor, __unsafe_unretained id); |
| 65 |
TRAIT_IS_TRUE(__has_trivial_constructor, HasStrong); |
| 66 |
TRAIT_IS_FALSE(__has_trivial_constructor, HasWeak); |
| 67 |
TRAIT_IS_TRUE(__has_trivial_constructor, HasUnsafeUnretained); |
| 68 |
|
| 69 |
// __has_trivial_destructor |
| 70 |
TRAIT_IS_TRUE(__has_trivial_destructor, __strong id); |
| 71 |
TRAIT_IS_FALSE(__has_trivial_destructor, __weak id); |
| 72 |
TRAIT_IS_TRUE(__has_trivial_destructor, __autoreleasing id); |
| 73 |
TRAIT_IS_TRUE(__has_trivial_destructor, __unsafe_unretained id); |
| 74 |
TRAIT_IS_TRUE(__has_trivial_destructor, HasStrong); |
| 75 |
TRAIT_IS_FALSE(__has_trivial_destructor, HasWeak); |
| 76 |
TRAIT_IS_TRUE(__has_trivial_destructor, HasUnsafeUnretained); |
| 77 |
|
| 78 |
// __is_literal |
| 79 |
TRAIT_IS_TRUE(__is_literal, __strong id); |
| 80 |
TRAIT_IS_TRUE(__is_literal, __weak id); |
| 81 |
TRAIT_IS_TRUE(__is_literal, __autoreleasing id); |
| 82 |
TRAIT_IS_TRUE(__is_literal, __unsafe_unretained id); |
| 83 |
|
| 84 |
// __is_literal_type |
| 85 |
TRAIT_IS_TRUE(__is_literal_type, __strong id); |
| 86 |
TRAIT_IS_TRUE(__is_literal_type, __weak id); |
| 87 |
TRAIT_IS_TRUE(__is_literal_type, __autoreleasing id); |
| 88 |
TRAIT_IS_TRUE(__is_literal_type, __unsafe_unretained id); |
| 89 |
|
| 90 |
// __is_pod |
| 91 |
TRAIT_IS_TRUE(__is_pod, __strong id); |
| 92 |
TRAIT_IS_FALSE(__is_pod, __weak id); |
| 93 |
TRAIT_IS_TRUE(__is_pod, __autoreleasing id); |
| 94 |
TRAIT_IS_TRUE(__is_pod, __unsafe_unretained id); |
| 95 |
TRAIT_IS_TRUE(__is_pod, HasStrong); |
| 96 |
TRAIT_IS_FALSE(__is_pod, HasWeak); |
| 97 |
TRAIT_IS_TRUE(__is_pod, HasUnsafeUnretained); |
| 98 |
|
| 99 |
// __is_trivial |
| 100 |
TRAIT_IS_TRUE(__is_trivial, __strong id); |
| 101 |
TRAIT_IS_FALSE(__is_trivial, __weak id); |
| 102 |
TRAIT_IS_TRUE(__is_trivial, __autoreleasing id); |
| 103 |
TRAIT_IS_TRUE(__is_trivial, __unsafe_unretained id); |
| 104 |
TRAIT_IS_TRUE(__is_trivial, HasStrong); |
| 105 |
TRAIT_IS_FALSE(__is_trivial, HasWeak); |
| 106 |
TRAIT_IS_TRUE(__is_trivial, HasUnsafeUnretained); |
| 107 |
|
| 108 |
// __is_scalar |
| 109 |
TRAIT_IS_TRUE(__is_scalar, __strong id); |
| 110 |
TRAIT_IS_FALSE(__is_scalar, __weak id); |
| 111 |
TRAIT_IS_TRUE(__is_scalar, __autoreleasing id); |
| 112 |
TRAIT_IS_TRUE(__is_scalar, __unsafe_unretained id); |
| 113 |
|
| 114 |
// __is_standard_layout |
| 115 |
TRAIT_IS_TRUE(__is_standard_layout, __strong id); |
| 116 |
TRAIT_IS_TRUE(__is_standard_layout, __weak id); |
| 117 |
TRAIT_IS_TRUE(__is_standard_layout, __autoreleasing id); |
| 118 |
TRAIT_IS_TRUE(__is_standard_layout, __unsafe_unretained id); |
| 119 |
|
| 120 |
// __is_trivally_assignable |
| 121 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __strong id); |
| 122 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __weak id); |
| 123 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __autoreleasing id); |
| 124 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __unsafe_unretained id); |
| 125 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __strong id&&); |
| 126 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __weak id&&); |
| 127 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __autoreleasing id&&); |
| 128 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __unsafe_unretained id&&); |
| 129 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __strong id); |
| 130 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __weak id); |
| 131 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __autoreleasing id); |
| 132 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __unsafe_unretained id); |
| 133 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __strong id&&); |
| 134 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __weak id&&); |
| 135 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __autoreleasing id&&); |
| 136 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __unsafe_unretained id&&); |
| 137 |
|
| 138 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __strong id); |
| 139 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __weak id); |
| 140 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __autoreleasing id); |
| 141 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __unsafe_unretained id); |
| 142 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __strong id&&); |
| 143 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __weak id&&); |
| 144 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __autoreleasing id&&); |
| 145 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __unsafe_unretained id&&); |
| 146 |
|
| 147 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __strong id); |
| 148 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __weak id); |
| 149 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __autoreleasing id); |
| 150 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __unsafe_unretained id); |
| 151 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __strong id&&); |
| 152 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __weak id&&); |
| 153 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __autoreleasing id&&); |
| 154 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __unsafe_unretained id&&); |
| 155 |
|
| 156 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, HasStrong&, HasStrong); |
| 157 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, HasStrong&, HasStrong&&); |
| 158 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, HasWeak&, HasWeak); |
| 159 |
TRAIT_IS_FALSE_2(__is_trivially_assignable, HasWeak&, HasWeak&&); |
| 160 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, HasUnsafeUnretained&, HasUnsafeUnretained); |
| 161 |
TRAIT_IS_TRUE_2(__is_trivially_assignable, HasUnsafeUnretained&, HasUnsafeUnretained&&); |
| 162 |
|
| 163 |
// __is_trivally_constructible |
| 164 |
TRAIT_IS_TRUE(__is_trivially_constructible, __strong id); |
| 165 |
TRAIT_IS_FALSE(__is_trivially_constructible, __weak id); |
| 166 |
TRAIT_IS_TRUE(__is_trivially_constructible, __autoreleasing id); |
| 167 |
TRAIT_IS_TRUE(__is_trivially_constructible, __unsafe_unretained id); |
| 168 |
|
| 169 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __strong id); |
| 170 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __weak id); |
| 171 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __autoreleasing id); |
| 172 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __unsafe_unretained id); |
| 173 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __strong id&&); |
| 174 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __weak id&&); |
| 175 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __autoreleasing id&&); |
| 176 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __unsafe_unretained id&&); |
| 177 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __strong id); |
| 178 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __weak id); |
| 179 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __autoreleasing id); |
| 180 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __unsafe_unretained id); |
| 181 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __strong id&&); |
| 182 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __weak id&&); |
| 183 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __autoreleasing id&&); |
| 184 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __unsafe_unretained id&&); |
| 185 |
|
| 186 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __strong id); |
| 187 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __weak id); |
| 188 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __autoreleasing id); |
| 189 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __unsafe_unretained id); |
| 190 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __strong id&&); |
| 191 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __weak id&&); |
| 192 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __autoreleasing id&&); |
| 193 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __unsafe_unretained id&&); |
| 194 |
|
| 195 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __strong id); |
| 196 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __weak id); |
| 197 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __autoreleasing id); |
| 198 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __unsafe_unretained id); |
| 199 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __strong id&&); |
| 200 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __weak id&&); |
| 201 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __autoreleasing id&&); |
| 202 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __unsafe_unretained id&&); |
| 203 |
|
| 204 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, HasStrong, HasStrong); |
| 205 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, HasStrong, HasStrong&&); |
| 206 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, HasWeak, HasWeak); |
| 207 |
TRAIT_IS_FALSE_2(__is_trivially_constructible, HasWeak, HasWeak&&); |
| 208 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, HasUnsafeUnretained, HasUnsafeUnretained); |
| 209 |
TRAIT_IS_TRUE_2(__is_trivially_constructible, HasUnsafeUnretained, HasUnsafeUnretained&&); |
| 210 |
|
| 211 |
// __is_trivially_relocatable |
| 212 |
TRAIT_IS_TRUE(__is_trivially_relocatable, __strong id); |
| 213 |
TRAIT_IS_FALSE(__is_trivially_relocatable, __weak id); |
| 214 |
TRAIT_IS_TRUE(__is_trivially_relocatable, __autoreleasing id); |
| 215 |
TRAIT_IS_TRUE(__is_trivially_relocatable, __unsafe_unretained id); |
| 216 |
TRAIT_IS_TRUE(__is_trivially_relocatable, HasStrong); |
| 217 |
TRAIT_IS_FALSE(__is_trivially_relocatable, HasWeak); |
| 218 |
TRAIT_IS_TRUE(__is_trivially_relocatable, HasUnsafeUnretained); |
| 219 |
|
| 220 |
|
| 221 |
static_assert(__builtin_is_cpp_trivially_relocatable(__weak id), ""); |
| 222 |
//expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(__weak id)'}}\ |
| 223 |
//expected-note@-1 {{'__weak id' is not trivially relocatable}}\ |
| 224 |
//expected-note@-1 {{because it has an ARC lifetime qualifier}} |