<sys/cdefs.h>: Decay expression passed to fallback

version of __generic()

This ensures that __generic() more closely matches _Generic() when
using the fallback version when _Generic() is not available (such as
GCC).

Co-authored by:	jrtc27
Reviewed by:	jrtc27
Differential Revision:	https://reviews.freebsd.org/D38215
This commit is contained in:
John Baldwin 2023-01-26 16:28:22 -08:00 committed by Sebastian Huber
parent 3b4f6217c3
commit b12934540f
1 changed files with 4 additions and 1 deletions

View File

@ -328,6 +328,9 @@
* __generic(). Unlike _Generic(), this macro can only distinguish
* between a single type, so it requires nested invocations to
* distinguish multiple cases.
*
* Note that the comma operator is used to force expr to decay in
* order to match _Generic().
*/
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
@ -337,7 +340,7 @@
#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
#define __generic(expr, t, yes, no) \
__builtin_choose_expr( \
__builtin_types_compatible_p(__typeof(expr), t), yes, no)
__builtin_types_compatible_p(__typeof((0, (expr))), t), yes, no)
#endif
/*