| 1 |
/* Examples of a mismatching function pointer type in |
| 2 |
legacy code that failed to compile with C23. |
| 3 |
|
| 4 |
Adapted from alsa-tools-1.2.11:envy24control/profiles.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) |
| 12 |
__attribute__ ((__nothrow__ , __leaf__)); |
| 13 |
|
| 14 |
void new_process(void) |
| 15 |
{ |
| 16 |
void (*int_stat)(); |
| 17 |
|
| 18 |
int_stat = signal(2, ((__sighandler_t) 1)); /* { dg-error "assignment to '\[^\n\r\]*' from incompatible pointer type '__sighandler_t' \\{aka '\[^\n\r\]*'\\}" } */ |
| 19 |
|
| 20 |
signal(2, int_stat); /* { dg-error "passing argument 2 of 'signal' from incompatible pointer type" } */ |
| 21 |
} |