<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/89844>89844</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy: Catch-22 with signals?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DarkTyger
</td>
</tr>
</table>
<pre>
Consider `t.cpp`:
``` cpp
#include <signal.h>
int main() {
struct sigaction action = {};
action.sa_handler = [](int signum ) {};
action.sa_flags = 0;
::sigemptyset( &action.sa_mask );
::sigaction( SIGUSR1, &action, nullptr );
}
```
Run:
clang-tidy --config-file=.clang-tidy src/t.cpp
Output:
```
t.cpp:1:10: warning: inclusion of deprecated C++ header 'signal.h'; consider using 'csignal' instead [modernize-deprecated-headers]
1 | #include <signal.h>
| ^~~~~~~~~~
| <csignal>
```
Change, then run again:
``` cpp
#include <csignal>
int main() {
struct sigaction action = {};
action.sa_handler = [](int signum ) {};
action.sa_flags = 0;
::sigemptyset( &action.sa_mask );
::sigaction( SIGUSR1, &action, nullptr );
}
```
Output:
```
t.cpp:4:10: warning: no header providing "sigaction" is directly included [misc-include-cleaner]
2 |
3 | int main() {
4 | struct sigaction action = {};
| ^
/home/jarvisd/repos/libdfsi/src/t.cpp:6:10: warning: no header providing "sa_handler" is directly included [misc-include-cleaner]
6 | action.sa_handler = [](int signum ) {};
| ^
/home/jarvisd/repos/libdfsi/src/t.cpp:8:5: warning: no header providing "sigemptyset" is directly included [misc-include-cleaner]
8 | ::sigemptyset( &action.sa_mask );
| ^
/home/jarvisd/repos/libdfsi/src/t.cpp:9:5: warning: no header providing "sigaction" is directly included [misc-include-cleaner]
9 | ::sigaction( SIGUSR1, &action, nullptr );
| ^
/home/jarvisd/repos/libdfsi/src/t.cpp:9:16: warning: no header providing "SIGUSR1" is directly included [misc-include-cleaner]
9 | ::sigaction( SIGUSR1, &action, nullptr );
| ^
```
As `sigaction` is in POSIX, not the C++ standard, is it useful to warn against including `signal.h`? Is there a viable alternative?
See also: https://thomastrapp.com/posts/signal-handlers-for-multithreaded-c++/
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vk2T2ygT_jX40iWXDLI-Djp47OitOeWtzG7V3rYwIIkEgQqQU97D_vYtJPlrMknFcUY1YxvR3XQ_z9MAdU42WogSrZ_Qeregg2-NLXfUfvnj2Ai72Bt-LLdGO8mFBZTGfsn6HqUxIhsU71B8-kzj6Q_C9PQKE6mZGrgARLZhHaqWLSIfrv2k9tBRqRHOES4AZU_Te3DeDsyDkw1lXhoN8xciu9Eq2yFysgWA06_Jauno3y3VXIWcg8NYHcJ5WC5kMnRwWu4m0MW9VrRxo3N8NR-qJhsnG9H1_uiERzgHhNOLX0fdlxD74nT2mYyCx8vz__58-bRCeHtxDgM9KNV7e-MfEryF-Bq_T4N-xQQwRXUTecmPEEXM6Fo2US2VQGS3vJpzliFcTXReuX8cfD_477E7DScnslmF_6AE-EqtlroJP0fOXaDK1MBFbwWjXnDYIvyE8BO0go5SwtlZEjhD5AnYSWWDk7oJBmyyQDgDqZ0XlAcmO8OF1fIfEV2iR1NUF1g-a2IFKAsA_1CGMD6j4frDv6fn9dz5QWR7yuos5Ld42bZUNyJw6luhwQ4aaBN0fmfbfLPYj7vmnrb5PS3zHh3zvi1zj8KTtxSuzUnEvTUHySe14qt0MUgHXFrBvDrCTOckXulYNL-ImBJUC3sjWjxp8Twm4_j7hAMks0Lv2TFvNb0-iQtXrekEwtVnag_ScYQrK3rjEK6U3PPaSYSr642DbNJ7EDpL7CGI0jn9B_f6b3v7ERxyRDbrnxbKpRkewCGf0_-lQ2ku_KGai7tq_g3NUbyu-Nf2h5s9_7HyV-nP1X9O7-Hq36H2t3bJjQu3vcsyaRwSlxr-__Hl-a8xuvHhcDsf7M5TzanlYS6YehicqAcF3owATQeg83PRIzDjCtOBHK6UFTy7ENMKoHCQdK8EUOWF1dT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