[Bug c/122591] _Countof has wrong return type (not size_t)
foss+gcc@alejandro-colomar.es
gcc-bugzilla@gcc.gnu.org
Fri Nov 7 02:24:00 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122591
--- Comment #2 from Alejandro Colomar <foss+gcc@alejandro-colomar.es> ---
Here's a reproducer that gives some more information:
alx@devuan:~/tmp$ cat c.c
#include <stddef.h>
int
main(void)
{
short i[1];
(void) _Generic(_Countof(i),
char: 1,
signed char: 2,
short: 3,
int: 4,
long: 5,
long long: 6,
unsigned char: 7,
unsigned short: 8,
unsigned int: 9,
unsigned long: 10,
unsigned long long: 11
);
typeof(_Countof(i)) *p = NULL;
size_t *q = p;
}
alx@devuan:~/tmp$ /opt/local/gnu/gcc/fwd_incomp4/bin/gcc c.c
c.c: In function ‘main’:
c.c:8:25: error: ‘_Generic’ selector of type ‘sizetype’ is not compatible with
any association
8 | (void) _Generic(_Countof(i),
| ^~~~~~~~
c.c:23:35: error: initialization of ‘size_t *’ {aka ‘long unsigned int *’} from
incompatible pointer type ‘sizetype *’ [-Wincompatible-pointer-types]
23 | size_t *q = p;
| ^
The issue seems to be that GCC is not connecting this sizetype --which seems to
be some GCC internal-- to the actual size_t. I don't know enough of GCC
internals to fix this.
More information about the Gcc-bugs
mailing list