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