Debian Codegraph @

clang-tools-extra/test/clang-tidy/checkers/concurrency/thread-canceltype-asynchronous.cpp

raw
1 // RUN: %check_clang_tidy %s concurrency-thread-canceltype-asynchronous %t
2
3 #define ONE (1 << 0)
4
5 #define PTHREAD_CANCEL_DEFERRED 0
6 // define the macro intentionally complex
7 #define PTHREAD_CANCEL_ASYNCHRONOUS ONE
8
9 #define ASYNCHR PTHREAD_CANCEL_ASYNCHRONOUS
10
11 int pthread_setcanceltype(int type, int *oldtype);
12
13 int main() {
14 int result, oldtype;
15
16 if ((result = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype)) != 0) {
17 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: the cancel type for a pthread should not be 'PTHREAD_CANCEL_ASYNCHRONOUS' [concurrency-thread-canceltype-asynchronous]
18 return 1;
19 }
20
21 if ((result = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype)) != 0) {
22 return 1;
23 }
24
25 return 0;
26 }
27
28 int f1() {
29 int result, oldtype;
30
31 if ((result = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype)) != 0) {
32 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: the cancel type for a pthread should not be 'PTHREAD_CANCEL_ASYNCHRONOUS' [concurrency-thread-canceltype-asynchronous]
33 return 1;
34 }
35
36 if ((result = pthread_setcanceltype(ASYNCHR, &oldtype)) != 0) {
37 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: the cancel type for a pthread should not be 'PTHREAD_CANCEL_ASYNCHRONOUS' [concurrency-thread-canceltype-asynchronous]
38 return 1;
39 }
40
41 return 0;
42 }
43
44 int f2(int type) {
45 int result, oldtype;
46
47 if ((result = pthread_setcanceltype(type, &oldtype)) != 0) {
48 return 1;
49 }
50
51 return 0;
52 }