| 1 |
// RUN: %clang_cc1 -std=c++11 -fobjc-runtime-has-weak -fobjc-weak -fobjc-arc -triple x86_64-apple-darwin -fsyntax-only -verify %s |
| 2 |
|
| 3 |
void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}} |
| 4 |
|
| 5 |
struct [[clang::trivial_abi]] S0 { |
| 6 |
int a; |
| 7 |
}; |
| 8 |
|
| 9 |
struct __attribute__((trivial_abi)) S1 { |
| 10 |
int a; |
| 11 |
}; |
| 12 |
|
| 13 |
struct __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 |
|
| 17 |
struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}} expected-note {{is polymorphic}} |
| 18 |
virtual void m(); |
| 19 |
}; |
| 20 |
|
| 21 |
struct 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 |
|
| 25 |
struct S4 { |
| 26 |
int a; |
| 27 |
}; |
| 28 |
|
| 29 |
struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}} expected-note {{has a virtual base}} |
| 30 |
}; |
| 31 |
|
| 32 |
struct __attribute__((trivial_abi)) S9 : public S4 { |
| 33 |
}; |
| 34 |
|
| 35 |
struct S6 { |
| 36 |
__weak id a; |
| 37 |
}; |
| 38 |
|
| 39 |
struct __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 |
|
| 43 |
struct __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 |
|
| 47 |
struct __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 |
|
| 51 |
struct __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 |
|
| 55 |
struct __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. |
| 60 |
template <class T> |
| 61 |
struct __attribute__((trivial_abi)) S10 { |
| 62 |
T p; |
| 63 |
}; |
| 64 |
|
| 65 |
S10<int *> p1; |
| 66 |
S10<__weak id> p2; |
| 67 |
|
| 68 |
template<> |
| 69 |
struct __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 |
|
| 73 |
template<class T> |
| 74 |
struct S14 { |
| 75 |
T a; |
| 76 |
__weak id b; |
| 77 |
}; |
| 78 |
|
| 79 |
template <class T> |
| 80 |
struct __attribute__((trivial_abi)) S15 : S14<T> { |
| 81 |
}; |
| 82 |
|
| 83 |
S15<int> s15; |
| 84 |
|
| 85 |
template <class T> |
| 86 |
struct __attribute__((trivial_abi)) S16 { |
| 87 |
S14<T> a; |
| 88 |
}; |
| 89 |
|
| 90 |
S16<int> s16; |
| 91 |
|
| 92 |
template <class T> |
| 93 |
struct __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 |
|
| 99 |
struct __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 |
|
| 103 |
S17<int> s17; |
| 104 |
|
| 105 |
namespace 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 |
} |