From 6c5402fee0b8b5da440c966832aa986142d99018 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 18 Oct 2025 21:13:43 +0200 Subject: [PATCH 1/3] lib/cast.h: const_cast(): Pass through other types It won't hurt; if the type is convertible, it will be accepted; and if it's not convertible, the compiler will reject it at call site. This 'default' branch allows converting a QChar** into a char**. Signed-off-by: Alejandro Colomar --- lib/cast.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cast.h b/lib/cast.h index e8e42e1a0b..6bb5971b5b 100644 --- a/lib/cast.h +++ b/lib/cast.h @@ -9,7 +9,7 @@ #include "config.h" -#define const_cast(T, p) _Generic(p, const T: (T) (p)) +#define const_cast(T, p) _Generic(p, const T: (T) (p), default: (p)) #endif // include guard From facb44cc2119ae2ebe919f6c30746757b634c4c7 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 18 Oct 2025 21:15:11 +0200 Subject: [PATCH 2/3] lib/atoi/a2i.h: Use const_cast() instead of a raw cast This allows grepping for casts more easily. It also reduces the damage of a bogus cast. Signed-off-by: Alejandro Colomar --- lib/atoi/a2i.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/atoi/a2i.h b/lib/atoi/a2i.h index 96d468ec40..eebb43db84 100644 --- a/lib/atoi/a2i.h +++ b/lib/atoi/a2i.h @@ -13,6 +13,7 @@ #include "atoi/strtoi/strtoi.h" #include "atoi/strtoi/strtou_noneg.h" +#include "cast.h" #include "typetraits.h" @@ -35,7 +36,7 @@ unsigned int: strtou_noneg, \ unsigned long: strtou_noneg, \ unsigned long long: strtou_noneg \ - )(s, (char **) endp_, base, min_, max_, &status); \ + )(s, const_cast(char **, endp_), base, min_, max_, &status); \ \ if (status != 0) \ errno = status; \ From aa4a07b21fcf7c14d06f182432e6ebe0b8d4a537 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 25 Nov 2025 14:03:55 +0100 Subject: [PATCH 3/3] lib/string/: Use QChar_of() to simplify some macros Signed-off-by: Alejandro Colomar --- lib/string/strcmp/strcaseprefix.h | 18 +++++------------- lib/string/strcmp/strprefix.h | 18 +++++------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/lib/string/strcmp/strcaseprefix.h b/lib/string/strcmp/strcaseprefix.h index b001076b6b..70bbaac70b 100644 --- a/lib/string/strcmp/strcaseprefix.h +++ b/lib/string/strcmp/strcaseprefix.h @@ -13,22 +13,14 @@ #include "attr.h" #include "cast.h" +#include "typetraits.h" -// string case-insensitive prefix +// strcaseprefix - string case-insensitive prefix #define strcaseprefix(s, prefix) \ -({ \ - const char *p_; \ - \ - p_ = strcaseprefix_(s, prefix); \ - \ - _Generic(s, \ - const char *: p_, \ - const void *: p_, \ - char *: const_cast(char *, p_), \ - void *: const_cast(char *, p_) \ - ); \ -}) +( \ + const_cast(QChar_of(s) *, strcaseprefix_(s, prefix)) \ +) ATTR_STRING(1) ATTR_STRING(2) diff --git a/lib/string/strcmp/strprefix.h b/lib/string/strcmp/strprefix.h index 3abffb5f4e..40449f3828 100644 --- a/lib/string/strcmp/strprefix.h +++ b/lib/string/strcmp/strprefix.h @@ -13,22 +13,14 @@ #include "attr.h" #include "cast.h" +#include "typetraits.h" -// string prefix +// strprefix - string prefix #define strprefix(s, prefix) \ -({ \ - const char *p_; \ - \ - p_ = strprefix_(s, prefix); \ - \ - _Generic(s, \ - const char *: p_, \ - const void *: p_, \ - char *: const_cast(char *, p_), \ - void *: const_cast(char *, p_) \ - ); \ -}) +( \ + const_cast(QChar_of(s) *, strprefix_(s, prefix)) \ +) ATTR_STRING(1)