| 1 |
/* Examples of a mismatching function pointer type in |
| 2 |
legacy code that got the wrong return type for the signal handler. |
| 3 |
|
| 4 |
Adapted from a52dec-0.7.4: src/a52dec.c which is GPLv2+. */ |
| 5 |
|
| 6 |
/* { dg-do compile } */ |
| 7 |
/* { dg-options "-std=c23 -pedantic-errors" } */ |
| 8 |
|
| 9 |
typedef void (*__sighandler_t) (int); /* { dg-message "'__sighandler_t' declared here" } */ |
| 10 |
|
| 11 |
extern __sighandler_t signal (int __sig, __sighandler_t __handler) /* { dg-message "expected '__sighandler_t' \\{aka '\[^\n\r\]*'\\} but argument is of type '\[^\n\r\]*'" } */ |
| 12 |
__attribute__ ((__nothrow__ , __leaf__)); |
| 13 |
|
| 14 |
/* Mismatching return type. */ |
| 15 |
#define RETSIGTYPE int |
| 16 |
static RETSIGTYPE signal_handler (int sig) /* { dg-message "'signal_handler' declared here" } */ |
| 17 |
{ |
| 18 |
} |
| 19 |
|
| 20 |
static void print_fps (int final) |
| 21 |
{ |
| 22 |
signal (42, signal_handler); /* { dg-error "passing argument 2 of 'signal' from incompatible pointer type" } */ |
| 23 |
} |