https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114731
--- Comment #5 from Alejandro Colomar <alx at kernel dot org> ---
Ahhh, sorry Sam. I had a mistake while writing the reproducer, and didn't
realize. I thought it was a side effect of something else.
Here's a fixed reproducer, with the fixed diagnostics.
$ cat g.c
#include <bsd/inttypes.h>
#include <errno.h>
#include <time.h>
#define a2i(TYPE, ...) \
( \
_Generic((TYPE) 0, \
long: a2sl(__VA_ARGS__), \
int: a2si(__VA_ARGS__) \
) \
)
#define a2sl(n, s, endp, base, min, max) \
( \
_Generic(endp, \
const char **: a2sl_c, \
char **: a2sl_nc, \
void *: a2sl_c \
)(n, s, endp, base, min, max) \
)
#define a2si(n, s, endp, base, min, max) \
( \
_Generic(endp, \
const char **: a2si_c, \
char **: a2si_nc, \
void *: a2si_c \
)(n, s, endp, base, min, max) \
)
static inline int a2sl_c(long *restrict n, const char *s,
const char **restrict endp, int base, long min, long max);
static inline int a2si_c(int *restrict n, const char *s,
const char **restrict endp, int base, int min, int max);
static inline int a2sl_nc(long *restrict n, const char *s,
char **restrict endp, int base, long min, long max);
static inline int a2si_nc(int *restrict n, const char *s,
char **restrict endp, int base, int min, int max);
static inline int
a2sl_c(long *restrict n, const char *s,
const char **restrict endp, int base, long min, long max)
{
return a2sl_nc(n, s, (char **) endp, base, min, max);
}
static inline int
a2si_c(int *restrict n, const char *s,
const char **restrict endp, int base, int min, int max)
{
return a2si_nc(n, s, (char **) endp, base, min, max);
}
static inline int
a2sl_nc(long *restrict n, const char *s,
char **restrict endp, int base, long min, long max)
{
int status;
*n = strtoi(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
static inline int
a2si_nc(int *restrict n, const char *s,
char **restrict endp, int base, int min, int max)
{
int status;
*n = strtoi(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
int
main(void)
{
time_t t;
a2i(time_t, &t, "42", NULL, 0, 0, 10);
}
alx@debian:~/tmp/c$ cc -Wall -Wextra g.c
g.c: In function ‘main’:
g.c:96:21: warning: passing argument 1 of ‘a2si_c’ from incompatible pointer
type [-Wincompatible-pointer-types]
96 | a2i(time_t, &t, "42", NULL, 0, 0, 10);
| ^~
| |
| time_t * {aka long int *}
g.c:30:11: note: in definition of macro ‘a2si’
30 | )(n, s, endp, base, min, max)
\
| ^
g.c:96:9: note: in expansion of macro ‘a2i’
96 | a2i(time_t, &t, "42", NULL, 0, 0, 10);
| ^~~
g.c:54:22: note: expected ‘int * restrict’ but argument is of type ‘time_t *’
{aka ‘long int *’}
54 | a2si_c(int *restrict n, const char *s,
| ~~~~~~~~~~~~~~^
/usr/bin/ld: /tmp/ccQQX6M9.o: in function `a2sl_nc':
g.c:(.text+0x86): undefined reference to `strtoi'
collect2: error: ld returned 1 exit status