|
|
Message-ID: <cover.1767877779.git.alx@kernel.org>
Date: Thu, 8 Jan 2026 14:25:06 +0100
From: Alejandro Colomar <alx@...nel.org>
To: musl@...ts.openwall.com
Cc: Alejandro Colomar <alx@...nel.org>, Markus Wichmann <nullplan@....net>,
Rich Felker <dalias@...c.org>, Luca Kellermann <mailto.luca.kellermann@...il.com>
Subject: [PATCH v6 0/1] include/string.h: Implement QChar and QVoid wrappers
standardized in C23
Hi!
In v6, I've fixed compatibility with old GCC versions. We don't really
need it, since we have this code wrapped around
'__STDC_VERSION__ >= 202311L', but it's easy, so let's do it. This
allows one to enable these macros also for earlier standards, if that
would be desirable for them.
Tested:
alx@...uan:~/tmp$ cat strchr.c
#include <stdio.h>
#include <string.h>
int
main(int argc, const char *argv[argc + 1])
{
char *p;
p = strchr(argv[0], 'u'); // -Wdiscarded-qualifiers
puts(p);
const char *cp;
cp = strchr(argv[0], 'u');
puts(cp);
&strchr(argv[0], 'u'); // error: lvalue required as unary ‘&’ operand
strchr(argv[0], 'u') = NULL; // error: lvalue required as left operand of assignment
int *i;
i = strchr(i, 'u'); // -Wincompatible-pointer-types
}
alx@...uan:~/tmp$ diff -U999 \
<(gcc-12 -Wall -Wextra -I /opt/local/musl/libc/qchar/include/ strchr.c |& cat) \
<(gcc -Wall -Wextra -I /opt/local/musl/libc/qchar/include/ strchr.c |& cat);
--- /dev/fd/63 2026-01-08 14:07:54.552877666 +0100
+++ /dev/fd/62 2026-01-08 14:07:54.552877666 +0100
@@ -1,19 +1,25 @@
strchr.c: In function ‘main’:
+strchr.c:9:11: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
+ 9 | p = strchr(argv[0], 'u'); // -Wdiscarded-qualifiers
+ | ^
strchr.c:17:9: error: lvalue required as unary ‘&’ operand
17 | &strchr(argv[0], 'u'); // error: lvalue required as unary ‘&’ operand
| ^
strchr.c:19:30: error: lvalue required as left operand of assignment
19 | strchr(argv[0], 'u') = NULL; // error: lvalue required as left operand of assignment
| ^
-strchr.c:23:20: warning: passing argument 1 of ‘strchr’ from incompatible pointer type [-Wincompatible-pointer-types]
+In file included from strchr.c:2:
+strchr.c:23:20: error: passing argument 1 of ‘strchr’ from incompatible pointer type [-Wincompatible-pointer-types]
23 | i = strchr(i, 'u'); // -Wincompatible-pointer-types
| ^
| |
| int *
-In file included from strchr.c:2:
+/opt/local/musl/libc/qchar/include/string.h:69:54: note: in definition of macro ‘strchr’
+ 69 | # define strchr(s, chr) ((__QCharptrof(s)) strchr(s, chr))
+ | ^
/opt/local/musl/libc/qchar/include/string.h:54:15: note: expected ‘const char *’ but argument is of type ‘int *’
54 | char *strchr (const char *, int);
| ^~~~~~~~~~~~
-strchr.c:23:11: warning: assignment to ‘int *’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]
+strchr.c:23:11: error: assignment to ‘int *’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]
23 | i = strchr(i, 'u'); // -Wincompatible-pointer-types
| ^
Rich, do I need to do anything else for this patch?
Have a lovely day!
Alex
Alejandro Colomar (1):
include/string.h: Implement QChar and QVoid wrappers standardized in
C23
include/string.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
Range-diff against v5:
1: b93da5be ! 1: f55c5681 include/string.h: Implement QChar and QVoid wrappers standardized in C23
@@ include/string.h: extern "C" {
#include <bits/alltypes.h>
-+#define __QVoidptrof(p) typeof(1?(p):(void*){})
++#define __QVoidptrof(p) typeof(1?(p):(void*){0})
+#define __QCharptrof(s) typeof \
+( \
-+ _Generic((__QVoidptrof(s)){}, \
++ _Generic((__QVoidptrof(s)){0}, \
+ const void *: (const char *) 0, \
+ void *: (char *) 0 \
+ ) \
--
2.51.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.