7
7
8
8
// --- CONSTRAINTS ---
9
9
10
- void nl1 () [[clang::nonblocking]]
10
+ void nb1 () [[clang::nonblocking]]
11
11
{
12
12
int *pInt = new int ; // expected-warning {{'nonblocking' function must not allocate or deallocate memory}}
13
13
delete pInt; // expected-warning {{'nonblocking' function must not allocate or deallocate memory}}
14
14
}
15
15
16
- void nl2 () [[clang::nonblocking]]
16
+ void nb2 () [[clang::nonblocking]]
17
17
{
18
18
static int global; // expected-warning {{'nonblocking' function must not have static locals}}
19
19
}
20
20
21
- void nl3 () [[clang::nonblocking]]
21
+ void nb3 () [[clang::nonblocking]]
22
22
{
23
23
try {
24
24
throw 42 ; // expected-warning {{'nonblocking' function must not throw or catch exceptions}}
@@ -27,35 +27,35 @@ void nl3() [[clang::nonblocking]]
27
27
}
28
28
}
29
29
30
- void nl4_inline () {}
31
- void nl4_not_inline (); // expected-note {{function cannot be inferred 'nonblocking' because it has no definition in this translation unit}}
30
+ void nb4_inline () {}
31
+ void nb4_not_inline (); // expected-note {{function cannot be inferred 'nonblocking' because it has no definition in this translation unit}}
32
32
33
- void nl4 () [[clang::nonblocking]]
33
+ void nb4 () [[clang::nonblocking]]
34
34
{
35
- nl4_inline (); // OK
36
- nl4_not_inline (); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}}
35
+ nb4_inline (); // OK
36
+ nb4_not_inline (); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}}
37
37
}
38
38
39
39
40
40
struct HasVirtual {
41
41
virtual void unsafe (); // expected-note {{virtual method cannot be inferred 'nonblocking'}}
42
42
};
43
43
44
- void nl5 () [[clang::nonblocking]]
44
+ void nb5 () [[clang::nonblocking]]
45
45
{
46
46
HasVirtual hv;
47
47
hv.unsafe (); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}}
48
48
}
49
49
50
- void nl6_unsafe (); // expected-note {{function cannot be inferred 'nonblocking' because it has no definition in this translation unit}}
51
- void nl6_transitively_unsafe ()
50
+ void nb6_unsafe (); // expected-note {{function cannot be inferred 'nonblocking' because it has no definition in this translation unit}}
51
+ void nb6_transitively_unsafe ()
52
52
{
53
- nl6_unsafe (); // expected-note {{function cannot be inferred 'nonblocking' because it calls non-'nonblocking' function}}
53
+ nb6_unsafe (); // expected-note {{function cannot be inferred 'nonblocking' because it calls non-'nonblocking' function}}
54
54
}
55
55
56
- void nl6 () [[clang::nonblocking]]
56
+ void nb6 () [[clang::nonblocking]]
57
57
{
58
- nl6_transitively_unsafe (); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}}
58
+ nb6_transitively_unsafe (); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}}
59
59
}
60
60
61
61
thread_local int tl_var{ 42 };
@@ -65,15 +65,15 @@ bool tl_test() [[clang::nonblocking]]
65
65
return tl_var > 0 ; // expected-warning {{'nonblocking' function must not use thread-local variables}}
66
66
}
67
67
68
- void nl7 ()
68
+ void nb7 ()
69
69
{
70
70
// Make sure we verify blocks
71
71
auto blk = ^() [[clang::nonblocking]] {
72
72
throw 42 ; // expected-warning {{'nonblocking' function must not throw or catch exceptions}}
73
73
};
74
74
}
75
75
76
- void nl8 ()
76
+ void nb8 ()
77
77
{
78
78
// Make sure we verify lambdas
79
79
auto lambda = []() [[clang::nonblocking]] {
@@ -111,7 +111,7 @@ void nl8()
111
111
}
112
112
};
113
113
114
- void nl9 () [[clang::nonblocking]]
114
+ void nb9 () [[clang::nonblocking]]
115
115
{
116
116
Adder<int >::add_explicit (1 , 2 );
117
117
Adder<int >::add_implicit (1 , 2 );
@@ -121,7 +121,7 @@ void nl9() [[clang::nonblocking]]
121
121
expected-note {{in template expansion here}}
122
122
}
123
123
124
- void nl10 (
124
+ void nb10 (
125
125
void (*fp1)(), // expected-note {{function pointer cannot be inferred 'nonblocking'}}
126
126
void (*fp2)() [[clang::nonblocking]]
127
127
) [[clang::nonblocking]]
@@ -131,20 +131,20 @@ void nl10(
131
131
}
132
132
133
133
// Interactions with nonblocking(false)
134
- void nl11_no_inference_1 () [[clang::nonblocking(false )]] // expected-note {{function does not permit inference of 'nonblocking'}}
134
+ void nb11_no_inference_1 () [[clang::nonblocking(false )]] // expected-note {{function does not permit inference of 'nonblocking'}}
135
135
{
136
136
}
137
- void nl11_no_inference_2 () [[clang::nonblocking(false )]]; // expected-note {{function does not permit inference of 'nonblocking'}}
137
+ void nb11_no_inference_2 () [[clang::nonblocking(false )]]; // expected-note {{function does not permit inference of 'nonblocking'}}
138
138
139
139
template <bool V>
140
140
struct ComputedNB {
141
141
void method () [[clang::nonblocking(V)]]; // expected-note {{function does not permit inference of 'nonblocking'}}
142
142
};
143
143
144
- void nl11 () [[clang::nonblocking]]
144
+ void nb11 () [[clang::nonblocking]]
145
145
{
146
- nl11_no_inference_1 (); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}}
147
- nl11_no_inference_2 (); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}}
146
+ nb11_no_inference_1 (); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}}
147
+ nb11_no_inference_2 (); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}}
148
148
149
149
ComputedNB<true > CNB_true;
150
150
CNB_true.method ();
@@ -154,11 +154,11 @@ void nl11() [[clang::nonblocking]]
154
154
}
155
155
156
156
// Verify that when attached to a redeclaration, the attribute successfully attaches.
157
- void nl12 () {
157
+ void nb12 () {
158
158
static int x; // expected-warning {{'nonblocking' function must not have static locals}}
159
159
}
160
- void nl12 () [[clang::nonblocking]];
161
- void nl13 () [[clang::nonblocking]] { nl12 (); }
160
+ void nb12 () [[clang::nonblocking]];
161
+ void nb13 () [[clang::nonblocking]] { nb12 (); }
162
162
163
163
// C++ member function pointers
164
164
struct PTMFTester {
@@ -175,21 +175,34 @@ void PTMFTester::convert() [[clang::nonblocking]]
175
175
}
176
176
177
177
// Block variables
178
- void nl17 (void (^blk)() [[clang::nonblocking]]) [[clang::nonblocking]] {
178
+ void nb17 (void (^blk)() [[clang::nonblocking]]) [[clang::nonblocking]] {
179
179
blk ();
180
180
}
181
181
182
182
// References to blocks
183
- void nl18 (void (^block)() [[clang::nonblocking]]) [[clang::nonblocking]]
183
+ void nb18 (void (^block)() [[clang::nonblocking]]) [[clang::nonblocking]]
184
184
{
185
185
auto &ref = block;
186
186
ref ();
187
187
}
188
188
189
+ // Verify traversal of implicit code paths - constructors and destructors.
190
+ struct Unsafe {
191
+ static void problem1 (); // expected-note {{function cannot be inferred 'nonblocking' because it has no definition in this translation unit}}
192
+ static void problem2 (); // expected-note {{function cannot be inferred 'nonblocking' because it has no definition in this translation unit}}
193
+
194
+ Unsafe () { problem1 (); } // expected-note {{function cannot be inferred 'nonblocking' because it calls non-'nonblocking' function 'Unsafe::problem1'}}
195
+ ~Unsafe () { problem2 (); } // expected-note {{function cannot be inferred 'nonblocking' because it calls non-'nonblocking' function 'Unsafe::problem2'}}
196
+ };
197
+
198
+ struct DerivedFromUnsafe : public Unsafe {
199
+ DerivedFromUnsafe () [[clang::nonblocking]] {} // expected-warning {{'nonblocking' function must not call non-'nonblocking' function 'Unsafe::Unsafe'}}
200
+ ~DerivedFromUnsafe () [[clang::nonblocking]] {} // expected-warning {{'nonblocking' function must not call non-'nonblocking' function 'Unsafe::~Unsafe'}}
201
+ };
189
202
190
203
// --- nonblocking implies noexcept ---
191
204
#pragma clang diagnostic warning "-Wperf-constraint-implies-noexcept"
192
205
193
- void nl19 () [[clang::nonblocking]] // expected-warning {{'nonblocking' function should be declared noexcept}}
206
+ void nb19 () [[clang::nonblocking]] // expected-warning {{'nonblocking' function should be declared noexcept}}
194
207
{
195
208
}
0 commit comments