Clang Project

clang_source_code/test/SemaObjCXX/attr-trivial-abi.mm
1// RUN: %clang_cc1 -std=c++11 -fobjc-runtime-has-weak -fobjc-weak -fobjc-arc -fsyntax-only -verify %s
2
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'}}
14  __weak id a;
15};
16
17struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}}
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'}}
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'}}
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'}}
40  __weak id a;
41};
42
43struct __attribute__((trivial_abi)) S13 { // expected-warning {{'trivial_abi' cannot be applied to 'S13'}}
44  __weak id a[2];
45};
46
47struct __attribute__((trivial_abi)) S7 { // expected-warning {{'trivial_abi' cannot be applied to 'S7'}}
48  S6 a;
49};
50
51struct __attribute__((trivial_abi)) S11 { // expected-warning {{'trivial_abi' cannot be applied to 'S11'}}
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>'}}
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'}}
94  __weak id a;
95};
96
97S17<int> s17;
98