git: 9d2f97981755 - main - <sys/cdefs.h>: Decay expression passed to fallback version of __generic()

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 27 Jan 2023 00:28:59 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=9d2f9798175586bdcd3423443804fbbc0cffb8d2

commit 9d2f9798175586bdcd3423443804fbbc0cffb8d2
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-01-27 00:28:22 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-01-27 00:28:22 +0000

    <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
---
 sys/sys/cdefs.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index 83ba7584e5b9..1de042339c3a 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -312,6 +312,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) || \
@@ -321,7 +324,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
 
 /*