Debian Codegraph @

clang/test/SemaCXX/no_destroy.cpp

raw
1 // RUN: %clang_cc1 -fc++-static-destructors=none -verify %s
2 // RUN: %clang_cc1 -fc++-static-destructors=thread-local -verify=expected,thread-local-dtors %s
3 // RUN: %clang_cc1 -verify=expected,thread-local-dtors,all-dtors %s
4 // RUN: %clang_cc1 -fexceptions -fc++-static-destructors=none -verify %s
5 // RUN: %clang_cc1 -fexceptions -fc++-static-destructors=thread-local -verify=expected,thread-local-dtors %s
6 // RUN: %clang_cc1 -fexceptions -verify=expected,thread-local-dtors,all-dtors %s
7
8 struct SecretDestructor {
9 private: ~SecretDestructor(); // expected-note + {{private}}
10 };
11
12 SecretDestructor sd1; // all-dtors-error{{private}}
13 thread_local SecretDestructor sd2; // thread-local-dtors-error{{private}}
14 void locals() {
15 static SecretDestructor sd3; // all-dtors-error{{private}}
16 thread_local SecretDestructor sd4; // thread-local-dtors-error{{private}}
17 }
18
19 [[clang::always_destroy]] SecretDestructor sd6; // expected-error{{private}}
20 [[clang::always_destroy]] thread_local SecretDestructor sd7; // expected-error{{private}}
21
22 [[clang::no_destroy]] SecretDestructor sd8;
23
24 int main() {
25 [[clang::no_destroy]] int p; // expected-error{{no_destroy attribute can only be applied to a variable with static or thread storage duration}}
26 [[clang::always_destroy]] int p2; // expected-error{{always_destroy attribute can only be applied to a variable with static or thread storage duration}}
27 [[clang::no_destroy]] static int p3;
28 [[clang::always_destroy]] static int p4;
29 }
30
31 [[clang::always_destroy]] [[clang::no_destroy]] int p; // expected-error{{'clang::no_destroy' and 'clang::always_destroy' attributes are not compatible}} // expected-note{{here}}
32 [[clang::no_destroy]] [[clang::always_destroy]] int p2; // expected-error{{'clang::always_destroy' and 'clang::no_destroy' attributes are not compatible}} // expected-note{{here}}
33
34 [[clang::always_destroy]] void f() {} // expected-warning{{'clang::always_destroy' attribute only applies to variables}}
35 struct [[clang::no_destroy]] DoesntApply {}; // expected-warning{{'clang::no_destroy' attribute only applies to variables}}
36
37 [[clang::no_destroy(0)]] int no_args; // expected-error{{'clang::no_destroy' attribute takes no arguments}}
38 [[clang::always_destroy(0)]] int no_args2; // expected-error{{'clang::always_destroy' attribute takes no arguments}}
39
40 // expected-error@+1 {{temporary of type 'SecretDestructor' has private destructor}}
41 SecretDestructor arr[10];
42
43 void local_arrays() {
44 // expected-error@+1 {{temporary of type 'SecretDestructor' has private destructor}}
45 static SecretDestructor arr2[10];
46 // expected-error@+1 {{temporary of type 'SecretDestructor' has private destructor}}
47 thread_local SecretDestructor arr3[10];
48 }
49
50 struct Base {
51 ~Base();
52 };
53 struct Derived1 {
54 Derived1(int);
55 Base b;
56 };
57 struct Derived2 {
58 Derived1 b;
59 };
60
61 void dontcrash() {
62 [[clang::no_destroy]] static Derived2 d2[] = {0, 0};
63 }
64
65 [[clang::no_destroy]] Derived2 d2[] = {0, 0};