1 | // RUN: %check_clang_tidy %s bugprone-bad-signal-to-kill-thread %t |
2 | |
3 | #define SIGTERM 15 |
4 | #define SIGINT 2 |
5 | using pthread_t = int; |
6 | using pthread_attr_t = int; |
7 | |
8 | int pthread_create(pthread_t *thread, const pthread_attr_t *attr, |
9 | void *(*start_routine)(void *), void *arg); |
10 | |
11 | int pthread_kill(pthread_t thread, int sig); |
12 | |
13 | int pthread_cancel(pthread_t thread); |
14 | |
15 | void *test_func_return_a_pointer(void *foo); |
16 | |
17 | int main() { |
18 | int result; |
19 | pthread_t thread; |
20 | |
21 | if ((result = pthread_create(thread: &thread, attr: nullptr, start_routine: test_func_return_a_pointer, arg: 0)) != 0) { |
22 | } |
23 | if ((result = pthread_kill(thread, SIGTERM)) != 0) { |
24 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: thread should not be terminated by raising the 'SIGTERM' signal [bugprone-bad-signal-to-kill-thread] |
25 | } |
26 | |
27 | //compliant solution |
28 | if ((result = pthread_cancel(thread)) != 0) { |
29 | } |
30 | |
31 | if ((result = pthread_kill(thread, SIGINT)) != 0) { |
32 | } |
33 | if ((result = pthread_kill(thread, sig: 0xF)) != 0) { |
34 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: thread should not be terminated by raising the 'SIGTERM' signal [bugprone-bad-signal-to-kill-thread] |
35 | } |
36 | |
37 | return 0; |
38 | } |
39 | |