Further testing showed that recent patch's use of compound literals also
runs afoul of GCC in unusual configurations, and it appears that C23
requires that it use 'constexpr' sometimes but not others. So let's drop
that and go to the simpler approach that NetBSD uses. This should also
work even with no-longer-supported Microsoft compilers. Proposed further
patch installed and attached.
I hope this is the last thing we need to change before the 2025a release.
From 4ab8692704842adee814a1c06c20e3bdb5d02574 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 14 Jan 2025 21:54:23 -0800
Subject: [PROPOSED] Fix bugs in -Wcast-qual pacification
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In reading the C23 standard more carefully, the recent -Wcast-qual
patch isn’t valid there, as ‘constexpr’ isn’t used when the
expression must be a constant expression. So, just use the
plain cast.
* localtime.c (TYPECVT): Remove. All uses replaced by plain casts.
(UNCONST): Fix typo in the !INTPTR_MAX case, by replacing char
const * with char *.
---
localtime.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/localtime.c b/localtime.c
index 9c185e66..96737ca6 100644
--- a/localtime.c
+++ b/localtime.c
@@ -37,20 +37,13 @@ static int lock(void) { return 0; }
static void unlock(void) { }
#endif
-/* Convert to TYPE the value of the expression EXPR. Use C99+ implicit
- conversion if available, as it is less powerful and therefore safer. */
-#if PORT_TO_C89
-# define TYPECVT(type, expr) ((type) (expr))
-#else
-# define TYPECVT(type, expr) ((type) {expr})
-#endif
-
/* Unless intptr_t is missing, pacify gcc -Wcast-qual on char const * exprs.
+ Use this carefully, as the casts disable type checking.
This is a macro so that it can be used in static initializers. */
#ifdef INTPTR_MAX
-# define UNCONST(a) ((char *) (intptr_t) TYPECVT (char const *, a))
+# define UNCONST(a) ((char *) (intptr_t) (a))
#else
-# define UNCONST(a) TYPECVT (char const *, a)
+# define UNCONST(a) ((char *) (a))
#endif
/* A signed type wider than int, so that we can add 1900 + tm_mon/12 to tm_year
--
2.45.2