public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: newlib@sourceware.org
Subject: [PATCH 1/2] <sys/cdefs.h>: Decay expression passed to fallback version of __generic()
Date: Mon,  7 Aug 2023 11:28:24 +0200	[thread overview]
Message-ID: <20230807092825.24459-2-sebastian.huber@embedded-brains.de> (raw)
In-Reply-To: <20230807092825.24459-1-sebastian.huber@embedded-brains.de>

From: John Baldwin <jhb@FreeBSD.org>

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

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index 720e700920..808498c50b 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -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
 
 /*
-- 
2.35.3


  reply	other threads:[~2023-08-07  9:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07  9:28 [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
2023-08-07  9:28 ` Sebastian Huber [this message]
2023-08-07  9:28 ` [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ Sebastian Huber
2023-08-07 13:15   ` Corinna Vinschen
2023-08-07 13:35     ` Sebastian Huber
2023-08-07 14:10       ` Corinna Vinschen
2023-08-07 10:00 ` [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230807092825.24459-2-sebastian.huber@embedded-brains.de \
    --to=sebastian.huber@embedded-brains.de \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).