aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2023-01-19 22:48:52 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2023-01-19 22:48:52 +0000
commit43703bc489ec504b947b869045c492ed38c1a69c (patch)
tree5203314412a2a702e4ef68b4f29051272c5baa06
parent16fbf0191243e7c9dff6615b1424b5d39186b36c (diff)
downloadsrc-43703bc489ec504b947b869045c492ed38c1a69c.tar.gz
src-43703bc489ec504b947b869045c492ed38c1a69c.zip
stdlib.h: Fix qsort_r compatibility with GCC 12.
GCC 12 (unlike GCC 9) does not match a function argument passed to the old qsort_r() API (as is used in the qsort_r_compat test) to a function pointer type via __generic. It treats the function type as a distinct type from a function pointer. As a workaround, add a second definition of qsort_r for GCC 12 which uses the bare function type. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D37410
-rw-r--r--include/stdlib.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/include/stdlib.h b/include/stdlib.h
index 754e8f5f5fd4..30d24aea1c10 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -352,9 +352,15 @@ void __qsort_r_compat(void *, size_t, size_t, void *,
__sym_compat(qsort_r, __qsort_r_compat, FBSD_1.0);
#endif
#if defined(__generic) && !defined(__cplusplus)
+#if __GNUC__ == 12
+#define qsort_r(base, nel, width, arg4, arg5) \
+ __generic(arg5, int (void *, const void *, const void *), \
+ __qsort_r_compat, qsort_r)(base, nel, width, arg4, arg5)
+#else
#define qsort_r(base, nel, width, arg4, arg5) \
__generic(arg5, int (*)(void *, const void *, const void *), \
__qsort_r_compat, qsort_r)(base, nel, width, arg4, arg5)
+#endif
#elif defined(__cplusplus)
__END_DECLS
extern "C++" {