Hi, Alexander Sosedkin wrote: > This breaks compiling gnutls with '-std=c99' (tested on Fedora 43 GCC 15.2.1): > uniwidth/width.c: In function 'uc_width': > uniwidth/width.c:61:19: error: unknown type name 'typeof'; did you > mean '__typeof__'? > 61 | if ((uc >> 9) < countof (nonspacing_table_ind)) > | ^~~~~~~
Thanks for the report. Generally it's better to compile GNU packages with -std=gnu99 instead of -std=c99, or with -std=gnu11 instead of -std=c11. But anyway, things ought to compile fine with -std=c99. Therefore I'm applying the fix below. > Another place suggesting __typeof__ for portability: > https://gcc.gnu.org/onlinedocs/gcc/Typeof.html '__typeof__' is a thing of the past. ISO C has standardized on 'typeof'. > What probably made it surface: > https://lists.gnu.org/archive/html/bug-gnulib/2026-03/msg00013.html Correct. 2026-03-03 Bruno Haible <[email protected]> Don't use 'typeof' built-in with -std=c99 or -std=c11. Reported by Alexander Sosedkin <[email protected]> in <https://lists.gnu.org/archive/html/bug-gnulib/2026-03/msg00019.html>. * lib/stdcountof.in.h (_gl_verify_is_array): Don't use the definition with typeof in strict C99 or C11 modes. * lib/string-desc.h (HAVE_TYPEOF): Don't define in strict C99 or C11 modes. diff --git a/lib/stdcountof.in.h b/lib/stdcountof.in.h index 1422629bf2..c2de1adce8 100644 --- a/lib/stdcountof.in.h +++ b/lib/stdcountof.in.h @@ -109,7 +109,8 @@ template <typename T> _gl_array_type_test<T> _gl_array_type_test_helper(T&); #else /* In C, we can use typeof and __builtin_types_compatible_p. */ /* Work around clang bug <https://github.com/llvm/llvm-project/issues/143284>. */ -# if _GL_GNUC_PREREQ (3, 1) && ! defined __clang__ /* || defined __clang__ */ +# if (_GL_GNUC_PREREQ (3, 1) && ! defined __clang__ /* || defined __clang__ */) \ + && !(defined __STRICT_ANSI__ && __STDC_VERSION__ < 202311L) /* but not with -std=c99 or -std=c11 */ # define _gl_verify_is_array(...) \ sizeof (struct { unsigned int _gl_verify_error_if_negative : __builtin_types_compatible_p (typeof (__VA_ARGS__), typeof (&*(__VA_ARGS__))) ? -1 : 1; }) # else diff --git a/lib/string-desc.h b/lib/string-desc.h index a3c17b8fdd..f716f0e27c 100644 --- a/lib/string-desc.h +++ b/lib/string-desc.h @@ -64,9 +64,10 @@ Test program: int f (int x) { typeof (x) y = x; return y; } */ -#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 1) > 3) /* both C and C++ mode */ \ - || (defined __clang__ && __clang_major__ >= 3 /* both C and C++ mode */ \ - && !(defined __cplusplus && !defined __GNUC__)) /* except for clang-cl in C++ mode */ \ +#if (((defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 1) > 3) /* both C and C++ mode */ \ + || (defined __clang__ && __clang_major__ >= 3 /* both C and C++ mode */ \ + && !(defined __cplusplus && !defined __GNUC__))) /* except for clang-cl in C++ mode */ \ + && !defined __STRICT_ANSI__) /* but not with -std=c99 or -std=c11 */ \ || (defined __SUNPRO_C && __SUNPRO_C >= 0x5110) /* C mode */ \ || __STDC_VERSION__ >= 202311L /* C mode */ # define HAVE_TYPEOF 1
