-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Open
Description
Consider t.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:
#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 = {};
| ^
t.cpp:6:10: warning: no header providing "sa_handler" is directly included [misc-include-cleaner]
6 | action.sa_handler = []( int signum ) {};
| ^
t.cpp:8:5: warning: no header providing "sigemptyset" is directly included [misc-include-cleaner]
8 | ::sigemptyset( &action.sa_mask );
| ^
t.cpp:9:5: warning: no header providing "sigaction" is directly included [misc-include-cleaner]
9 | ::sigaction( SIGUSR1, &action, nullptr );
| ^
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++/