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