136 lines · plain
1// RUN: %clang_cc1 -std=c++11 -fobjc-runtime-has-weak -fobjc-weak -fobjc-arc -triple x86_64-apple-darwin -fsyntax-only -verify %s2 3void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}4 5struct [[clang::trivial_abi]] S0 {6 int a;7};8 9struct __attribute__((trivial_abi)) S1 {10 int a;11};12 13struct __attribute__((trivial_abi)) S2 { // expected-warning {{'trivial_abi' cannot be applied to 'S2'}} expected-note {{has a __weak field}}14 __weak id a;15};16 17struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}} expected-note {{is polymorphic}}18 virtual void m();19};20 21struct S3_2 {22 virtual void m();23} __attribute__((trivial_abi)); // expected-warning {{'trivial_abi' cannot be applied to 'S3_2'}} expected-note {{is polymorphic}}24 25struct S4 {26 int a;27};28 29struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}} expected-note {{has a virtual base}}30};31 32struct __attribute__((trivial_abi)) S9 : public S4 {33};34 35struct S6 {36 __weak id a;37};38 39struct __attribute__((trivial_abi)) S12 { // expected-warning {{'trivial_abi' cannot be applied to 'S12'}} expected-note {{has a __weak field}}40 __weak id a;41};42 43struct __attribute__((trivial_abi)) S13 { // expected-warning {{'trivial_abi' cannot be applied to 'S13'}} expected-note {{has a __weak field}}44 __weak id a[2];45};46 47struct __attribute__((trivial_abi)) S7 { // expected-warning {{'trivial_abi' cannot be applied to 'S7'}} expected-note {{has a field of a non-trivial class type}}48 S6 a;49};50 51struct __attribute__((trivial_abi)) S11 { // expected-warning {{'trivial_abi' cannot be applied to 'S11'}} expected-note {{has a field of a non-trivial class type}}52 S6 a[2];53};54 55struct __attribute__((trivial_abi(1))) S8 { // expected-error {{'trivial_abi' attribute takes no arguments}}56 int a;57};58 59// Do not warn when 'trivial_abi' is used to annotate a template class.60template <class T>61struct __attribute__((trivial_abi)) S10 {62 T p;63};64 65S10<int *> p1;66S10<__weak id> p2;67 68template<>69struct __attribute__((trivial_abi)) S10<id> { // expected-warning {{'trivial_abi' cannot be applied to 'S10<id>'}} expected-note {{has a __weak field}}70 __weak id a;71};72 73template<class T>74struct S14 {75 T a;76 __weak id b;77};78 79template <class T>80struct __attribute__((trivial_abi)) S15 : S14<T> {81};82 83S15<int> s15;84 85template <class T>86struct __attribute__((trivial_abi)) S16 {87 S14<T> a;88};89 90S16<int> s16;91 92template <class T>93struct __attribute__((trivial_abi)) S17 { // expected-warning {{'trivial_abi' cannot be applied to 'S17'}} expected-note {{has a __weak field}}94 S17();95 S17(S17 &&);96 __weak id a;97};98 99struct __attribute__((trivial_abi)) S18 { // expected-warning {{'trivial_abi' cannot be applied to 'S18'}} expected-note {{has a __weak field}}100 __weak id a;101};102 103S17<int> s17;104 105namespace deletedCopyMoveConstructor {106 struct __attribute__((trivial_abi)) CopyMoveDeleted { // expected-warning {{'trivial_abi' cannot be applied to 'CopyMoveDeleted'}} expected-note {{copy constructors and move constructors are all deleted}}107 CopyMoveDeleted(const CopyMoveDeleted &) = delete;108 CopyMoveDeleted(CopyMoveDeleted &&) = delete;109 };110 111 struct __attribute__((trivial_abi)) S18 { // expected-warning {{'trivial_abi' cannot be applied to 'S18'}} \112 // expected-note {{'trivial_abi' is disallowed on 'S18' because it has a field of a non-trivial class type}}113 CopyMoveDeleted a;114 };115 116 struct __attribute__((trivial_abi)) CopyDeleted {117 CopyDeleted(const CopyDeleted &) = delete;118 CopyDeleted(CopyDeleted &&) = default;119 };120 121 struct __attribute__((trivial_abi)) MoveDeleted {122 MoveDeleted(const MoveDeleted &) = default;123 MoveDeleted(MoveDeleted &&) = delete;124 };125 126 struct __attribute__((trivial_abi)) S19 { // expected-warning {{'trivial_abi' cannot be applied to 'S19'}} expected-note {{copy constructors and move constructors are all deleted}}127 CopyDeleted a;128 MoveDeleted b;129 };130 131 // This is fine since the move constructor isn't deleted.132 struct __attribute__((trivial_abi)) S20 {133 int &&a; // a member of rvalue reference type deletes the copy constructor.134 };135}136