brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.9 KiB · 91683c9 Raw
225 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -fobjc-weak -fobjc-runtime-has-weak -verify -std=c++11 %s -Wno-deprecated-builtins2 3// Check the results of the various type-trait query functions on4// 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 11struct HasStrong { id obj; };12struct HasWeak { __weak id obj; };13struct HasUnsafeUnretained { __unsafe_unretained id obj; };14 15// __has_nothrow_assign16TRAIT_IS_TRUE(__has_nothrow_assign, __strong id);17TRAIT_IS_TRUE(__has_nothrow_assign, __weak id);18TRAIT_IS_TRUE(__has_nothrow_assign, __autoreleasing id);19TRAIT_IS_TRUE(__has_nothrow_assign, __unsafe_unretained id);20TRAIT_IS_TRUE(__has_nothrow_assign, HasStrong);21TRAIT_IS_TRUE(__has_nothrow_assign, HasWeak);22TRAIT_IS_TRUE(__has_nothrow_assign, HasUnsafeUnretained);23 24// __has_nothrow_copy25TRAIT_IS_TRUE(__has_nothrow_copy, __strong id);26TRAIT_IS_TRUE(__has_nothrow_copy, __weak id);27TRAIT_IS_TRUE(__has_nothrow_copy, __autoreleasing id);28TRAIT_IS_TRUE(__has_nothrow_copy, __unsafe_unretained id);29TRAIT_IS_TRUE(__has_nothrow_copy, HasStrong);30TRAIT_IS_TRUE(__has_nothrow_copy, HasWeak);31TRAIT_IS_TRUE(__has_nothrow_copy, HasUnsafeUnretained);32 33// __has_nothrow_constructor34TRAIT_IS_TRUE(__has_nothrow_constructor, __strong id);35TRAIT_IS_TRUE(__has_nothrow_constructor, __weak id);36TRAIT_IS_TRUE(__has_nothrow_constructor, __autoreleasing id);37TRAIT_IS_TRUE(__has_nothrow_constructor, __unsafe_unretained id);38TRAIT_IS_TRUE(__has_nothrow_constructor, HasStrong);39TRAIT_IS_TRUE(__has_nothrow_constructor, HasWeak);40TRAIT_IS_TRUE(__has_nothrow_constructor, HasUnsafeUnretained);41 42// __has_trivial_assign43TRAIT_IS_TRUE(__has_trivial_assign, __strong id);44TRAIT_IS_FALSE(__has_trivial_assign, __weak id);45TRAIT_IS_TRUE(__has_trivial_assign, __autoreleasing id);46TRAIT_IS_TRUE(__has_trivial_assign, __unsafe_unretained id);47TRAIT_IS_TRUE(__has_trivial_assign, HasStrong);48TRAIT_IS_FALSE(__has_trivial_assign, HasWeak);49TRAIT_IS_TRUE(__has_trivial_assign, HasUnsafeUnretained);50 51// __has_trivial_copy52TRAIT_IS_TRUE(__has_trivial_copy, __strong id);53TRAIT_IS_FALSE(__has_trivial_copy, __weak id);54TRAIT_IS_TRUE(__has_trivial_copy, __autoreleasing id);55TRAIT_IS_TRUE(__has_trivial_copy, __unsafe_unretained id);56TRAIT_IS_TRUE(__has_trivial_copy, HasStrong);57TRAIT_IS_FALSE(__has_trivial_copy, HasWeak);58TRAIT_IS_TRUE(__has_trivial_copy, HasUnsafeUnretained);59 60// __has_trivial_constructor61TRAIT_IS_TRUE(__has_trivial_constructor, __strong id);62TRAIT_IS_FALSE(__has_trivial_constructor, __weak id);63TRAIT_IS_TRUE(__has_trivial_constructor, __autoreleasing id);64TRAIT_IS_TRUE(__has_trivial_constructor, __unsafe_unretained id);65TRAIT_IS_TRUE(__has_trivial_constructor, HasStrong);66TRAIT_IS_FALSE(__has_trivial_constructor, HasWeak);67TRAIT_IS_TRUE(__has_trivial_constructor, HasUnsafeUnretained);68 69// __has_trivial_destructor70TRAIT_IS_TRUE(__has_trivial_destructor, __strong id);71TRAIT_IS_FALSE(__has_trivial_destructor, __weak id);72TRAIT_IS_TRUE(__has_trivial_destructor, __autoreleasing id);73TRAIT_IS_TRUE(__has_trivial_destructor, __unsafe_unretained id);74TRAIT_IS_TRUE(__has_trivial_destructor, HasStrong);75TRAIT_IS_FALSE(__has_trivial_destructor, HasWeak);76TRAIT_IS_TRUE(__has_trivial_destructor, HasUnsafeUnretained);77 78// __is_literal79TRAIT_IS_TRUE(__is_literal, __strong id);80TRAIT_IS_TRUE(__is_literal, __weak id);81TRAIT_IS_TRUE(__is_literal, __autoreleasing id);82TRAIT_IS_TRUE(__is_literal, __unsafe_unretained id);83 84// __is_literal_type85TRAIT_IS_TRUE(__is_literal_type, __strong id);86TRAIT_IS_TRUE(__is_literal_type, __weak id);87TRAIT_IS_TRUE(__is_literal_type, __autoreleasing id);88TRAIT_IS_TRUE(__is_literal_type, __unsafe_unretained id);89 90// __is_pod91TRAIT_IS_TRUE(__is_pod, __strong id);92TRAIT_IS_FALSE(__is_pod, __weak id);93TRAIT_IS_TRUE(__is_pod, __autoreleasing id);94TRAIT_IS_TRUE(__is_pod, __unsafe_unretained id);95TRAIT_IS_TRUE(__is_pod, HasStrong);96TRAIT_IS_FALSE(__is_pod, HasWeak);97TRAIT_IS_TRUE(__is_pod, HasUnsafeUnretained);98 99// __is_trivial100TRAIT_IS_TRUE(__is_trivial, __strong id);101TRAIT_IS_FALSE(__is_trivial, __weak id);102TRAIT_IS_TRUE(__is_trivial, __autoreleasing id);103TRAIT_IS_TRUE(__is_trivial, __unsafe_unretained id);104TRAIT_IS_TRUE(__is_trivial, HasStrong);105TRAIT_IS_FALSE(__is_trivial, HasWeak);106TRAIT_IS_TRUE(__is_trivial, HasUnsafeUnretained);107 108// __is_scalar109TRAIT_IS_TRUE(__is_scalar, __strong id);110TRAIT_IS_FALSE(__is_scalar, __weak id);111TRAIT_IS_TRUE(__is_scalar, __autoreleasing id);112TRAIT_IS_TRUE(__is_scalar, __unsafe_unretained id);113 114// __is_standard_layout115TRAIT_IS_TRUE(__is_standard_layout, __strong id);116TRAIT_IS_TRUE(__is_standard_layout, __weak id);117TRAIT_IS_TRUE(__is_standard_layout, __autoreleasing id);118TRAIT_IS_TRUE(__is_standard_layout, __unsafe_unretained id);119 120// __is_trivally_assignable121TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __strong id);122TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __weak id);123TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __autoreleasing id);124TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __unsafe_unretained id);125TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __strong id&&);126TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __weak id&&);127TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __autoreleasing id&&);128TRAIT_IS_TRUE_2(__is_trivially_assignable, __strong id&, __unsafe_unretained id&&);129TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __strong id);130TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __weak id);131TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __autoreleasing id);132TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __unsafe_unretained id);133TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __strong id&&);134TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __weak id&&);135TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __autoreleasing id&&);136TRAIT_IS_FALSE_2(__is_trivially_assignable, __weak id&, __unsafe_unretained id&&);137 138TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __strong id);139TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __weak id);140TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __autoreleasing id);141TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __unsafe_unretained id);142TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __strong id&&);143TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __weak id&&);144TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __autoreleasing id&&);145TRAIT_IS_TRUE_2(__is_trivially_assignable, __autoreleasing id&, __unsafe_unretained id&&);146 147TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __strong id);148TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __weak id);149TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __autoreleasing id);150TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __unsafe_unretained id);151TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __strong id&&);152TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __weak id&&);153TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __autoreleasing id&&);154TRAIT_IS_TRUE_2(__is_trivially_assignable, __unsafe_unretained id&, __unsafe_unretained id&&);155 156TRAIT_IS_TRUE_2(__is_trivially_assignable, HasStrong&, HasStrong);157TRAIT_IS_TRUE_2(__is_trivially_assignable, HasStrong&, HasStrong&&);158TRAIT_IS_FALSE_2(__is_trivially_assignable, HasWeak&, HasWeak);159TRAIT_IS_FALSE_2(__is_trivially_assignable, HasWeak&, HasWeak&&);160TRAIT_IS_TRUE_2(__is_trivially_assignable, HasUnsafeUnretained&, HasUnsafeUnretained);161TRAIT_IS_TRUE_2(__is_trivially_assignable, HasUnsafeUnretained&, HasUnsafeUnretained&&);162 163// __is_trivally_constructible164TRAIT_IS_TRUE(__is_trivially_constructible, __strong id);165TRAIT_IS_FALSE(__is_trivially_constructible, __weak id);166TRAIT_IS_TRUE(__is_trivially_constructible, __autoreleasing id);167TRAIT_IS_TRUE(__is_trivially_constructible, __unsafe_unretained id);168 169TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __strong id);170TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __weak id);171TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __autoreleasing id);172TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __unsafe_unretained id);173TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __strong id&&);174TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __weak id&&);175TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __autoreleasing id&&);176TRAIT_IS_TRUE_2(__is_trivially_constructible, __strong id, __unsafe_unretained id&&);177TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __strong id);178TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __weak id);179TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __autoreleasing id);180TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __unsafe_unretained id);181TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __strong id&&);182TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __weak id&&);183TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __autoreleasing id&&);184TRAIT_IS_FALSE_2(__is_trivially_constructible, __weak id, __unsafe_unretained id&&);185 186TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __strong id);187TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __weak id);188TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __autoreleasing id);189TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __unsafe_unretained id);190TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __strong id&&);191TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __weak id&&);192TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __autoreleasing id&&);193TRAIT_IS_TRUE_2(__is_trivially_constructible, __autoreleasing id, __unsafe_unretained id&&);194 195TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __strong id);196TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __weak id);197TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __autoreleasing id);198TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __unsafe_unretained id);199TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __strong id&&);200TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __weak id&&);201TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __autoreleasing id&&);202TRAIT_IS_TRUE_2(__is_trivially_constructible, __unsafe_unretained id, __unsafe_unretained id&&);203 204TRAIT_IS_TRUE_2(__is_trivially_constructible, HasStrong, HasStrong);205TRAIT_IS_TRUE_2(__is_trivially_constructible, HasStrong, HasStrong&&);206TRAIT_IS_FALSE_2(__is_trivially_constructible, HasWeak, HasWeak);207TRAIT_IS_FALSE_2(__is_trivially_constructible, HasWeak, HasWeak&&);208TRAIT_IS_TRUE_2(__is_trivially_constructible, HasUnsafeUnretained, HasUnsafeUnretained);209TRAIT_IS_TRUE_2(__is_trivially_constructible, HasUnsafeUnretained, HasUnsafeUnretained&&);210 211// __is_trivially_relocatable212TRAIT_IS_TRUE(__is_trivially_relocatable, __strong id);213TRAIT_IS_FALSE(__is_trivially_relocatable, __weak id);214TRAIT_IS_TRUE(__is_trivially_relocatable, __autoreleasing id);215TRAIT_IS_TRUE(__is_trivially_relocatable, __unsafe_unretained id);216TRAIT_IS_TRUE(__is_trivially_relocatable, HasStrong);217TRAIT_IS_FALSE(__is_trivially_relocatable, HasWeak);218TRAIT_IS_TRUE(__is_trivially_relocatable, HasUnsafeUnretained);219 220 221static_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}}225