> +#   define mbsstr(h,n) (typeof(h)) mbsstr ((h), (n))

Oops, this does not work when the argument is an array:
  error: cast specifies array type

We need to convert the array argument to a pointer first.


2025-02-09  Bruno Haible  <br...@clisp.org>

        mbsstr, mbscasestr, mbspcasecmp: Fix use of 'typeof'.
        * lib/string.in.h (mbsstr, mbspcasecmp, mbscasestr): Perform array to
        pointer conversion in argument of 'typeof'.

diff --git a/lib/string.in.h b/lib/string.in.h
index bfe949cf84..d4c7df6258 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -1193,7 +1193,7 @@ template <>
 #   define mbsstr mbsstr_template
 #  else
 #   if __STDC_VERSION__ >= 202311
-#    define mbsstr(h,n) (typeof(h)) mbsstr ((h), (n))
+#    define mbsstr(h,n) (typeof ((h) + 0)) mbsstr ((h), (n))
 #   elif ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
           || defined __ICC  || defined __TINYC__)
 #    define mbsstr(h,n) \
@@ -1259,7 +1259,7 @@ template <>
 #   define mbspcasecmp mbspcasecmp_template
 #  else
 #   if __STDC_VERSION__ >= 202311
-#    define mbspcasecmp(s,p) (typeof(s)) mbspcasecmp ((s), (p))
+#    define mbspcasecmp(s,p) (typeof ((s) + 0)) mbspcasecmp ((s), (p))
 #   elif ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
           || defined __ICC  || defined __TINYC__)
 #    define mbspcasecmp(s,p) \
@@ -1295,7 +1295,7 @@ template <>
 #   define mbscasestr mbscasestr_template
 #  else
 #   if __STDC_VERSION__ >= 202311
-#    define mbscasestr(h,n) (typeof(h)) mbscasestr ((h), (n))
+#    define mbscasestr(h,n) (typeof ((h) + 0)) mbscasestr ((h), (n))
 #   elif ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
           || defined __ICC  || defined __TINYC__)
 #    define mbscasestr(h,n) \




Reply via email to