Kirill Makurin wrote in <https://lists.gnu.org/archive/html/bug-gettext/2026-01/msg00008.html>:
> H:\releases\gettext-1.0-pre1\gettext-runtime\src\envsubst.c(540,19): error: > call to undeclared function 'typeof'; ISO C99 and later do not support > implicit function declarations [-Wimplicit-function-declaration] > 540 | sd_fwrite (stdout, sb_contents (&buffer)); > | ^ > H:\releases\gettext-1.0-pre1\gettext-runtime\gnulib-lib\string-desc.h(617,6): > note: expanded from macro 'sd_fwrite' > 617 | typeof (s) _s_ = (s); \ > | ^ > H:\releases\gettext-1.0-pre1\gettext-runtime\src\envsubst.c(540,19): error: > expected ';' after _expression_ > H:\releases\gettext-1.0-pre1\gettext-runtime\gnulib-lib\string-desc.h(617,17): > note: expanded from macro 'sd_fwrite' > 617 | typeof (s) _s_ = (s); \ > | ^ and in <https://lists.gnu.org/archive/html/bug-gettext/2026-01/msg00020.html>: > In C++ mode clang-cl.exe used C++14 by default and properly reports it > in __cplusplus macro. However, it seem like it does not understand extensions > like `typeof` by default. These two patches should fix it. 2026-01-11 Bruno Haible <[email protected]> string-desc: Avoid compilation error with clang-cl in C++ mode. Reported by Kirill Makurin <[email protected]> in <https://lists.gnu.org/archive/html/bug-gettext/2026-01/msg00020.html>. * lib/string-desc.h (HAVE_TYPEOF): New macro. (HAVE_RW_STRING_DESC): Test also HAVE_TYPEOF. string-desc: Revisit feature tests regarding C++. * lib/string-desc.h (HAVE_STATEMENT_EXPRESSIONS): Also define with SunPRO C++. (HAVE__GENERIC): Don't define with GNU C++. Define in ISO C 11 or newer.
From 9ebcd7c8545f1c3781ec6027122b0fe16d547266 Mon Sep 17 00:00:00 2001 From: Bruno Haible <[email protected]> Date: Sun, 11 Jan 2026 22:58:14 +0100 Subject: [PATCH 1/2] string-desc: Revisit feature tests regarding C++. * lib/string-desc.h (HAVE_STATEMENT_EXPRESSIONS): Also define with SunPRO C++. (HAVE__GENERIC): Don't define with GNU C++. Define in ISO C 11 or newer. --- ChangeLog | 7 +++++++ lib/string-desc.h | 21 ++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9fdc1b301d..d5ca627ee5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2026-01-11 Bruno Haible <[email protected]> + + string-desc: Revisit feature tests regarding C++. + * lib/string-desc.h (HAVE_STATEMENT_EXPRESSIONS): Also define with + SunPRO C++. + (HAVE__GENERIC): Don't define with GNU C++. Define in ISO C 11 or newer. + 2026-01-10 P??draig Brady <[email protected]> selinux-h: warning about missing libselinux on modern systems diff --git a/lib/string-desc.h b/lib/string-desc.h index db4570695f..4eaafdd95c 100644 --- a/lib/string-desc.h +++ b/lib/string-desc.h @@ -42,8 +42,10 @@ Test program: int f (int x) { return ({ x; x; }); } */ -#if defined __GNUC__ || defined __clang__ \ - || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) +#if defined __GNUC__ /* both C and C++ mode */ \ + || defined __clang__ /* both C and C++ mode */ \ + || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) /* C mode */ \ + || (defined __SUNPRO_CC && __SUNPRO_CC >= 0x5150) /* C++ mode */ # define HAVE_STATEMENT_EXPRESSIONS 1 #endif @@ -51,9 +53,10 @@ Test program: int f (int x) { return _Generic (x, char *: 2, int: 3); } */ -#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 9) > 4) \ - || (defined __clang__ && __clang_major__ >= 3) \ - || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) +#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined __cplusplus) /* C mode */ \ + || (defined __clang__ && __clang_major__ >= 3) /* both C and C++ mode */ \ + || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) /* C mode */ \ + || __STDC_VERSION__ >= 201112L /* C mode */ # define HAVE__GENERIC 1 #endif @@ -64,8 +67,8 @@ Test program: int f (int x) { return __builtin_choose_expr (sizeof (x) == 4, 2, 3); } */ -#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 1) > 3) \ - || (defined __clang__ && __clang_major__ >= 3) +#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 1) > 3) /* both C and C++ mode */ \ + || (defined __clang__ && __clang_major__ >= 3) /* both C and C++ mode */ # define HAVE_BUILTIN_CHOOSE_EXPR 1 #endif @@ -77,8 +80,8 @@ Test program: int i, v[__builtin_constant_p ("x") > __builtin_constant_p (i) ? 1 : -1]; */ -#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 1) > 3) \ - || (defined __clang__ && __clang_major__ >= 4) +#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 1) > 3) /* both C and C++ mode */ \ + || (defined __clang__ && __clang_major__ >= 4) /* both C and C++ mode */ # define HAVE_BUILTIN_CONSTANT_P 1 #endif -- 2.52.0
>From b5cad9c36752025c252f715a7111e751d9f43717 Mon Sep 17 00:00:00 2001 From: Bruno Haible <[email protected]> Date: Sun, 11 Jan 2026 22:58:51 +0100 Subject: [PATCH 2/2] string-desc: Avoid compilation error with clang-cl in C++ mode. Reported by Kirill Makurin <[email protected]> in <https://lists.gnu.org/archive/html/bug-gettext/2026-01/msg00020.html>. * lib/string-desc.h (HAVE_TYPEOF): New macro. (HAVE_RW_STRING_DESC): Test also HAVE_TYPEOF. --- ChangeLog | 6 ++++++ lib/string-desc.h | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d5ca627ee5..5216c6ac8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2026-01-11 Bruno Haible <[email protected]> + string-desc: Avoid compilation error with clang-cl in C++ mode. + Reported by Kirill Makurin <[email protected]> in + <https://lists.gnu.org/archive/html/bug-gettext/2026-01/msg00020.html>. + * lib/string-desc.h (HAVE_TYPEOF): New macro. + (HAVE_RW_STRING_DESC): Test also HAVE_TYPEOF. + string-desc: Revisit feature tests regarding C++. * lib/string-desc.h (HAVE_STATEMENT_EXPRESSIONS): Also define with SunPRO C++. diff --git a/lib/string-desc.h b/lib/string-desc.h index 4eaafdd95c..24c38ccf35 100644 --- a/lib/string-desc.h +++ b/lib/string-desc.h @@ -60,6 +60,18 @@ # define HAVE__GENERIC 1 #endif +/* Whether the compiler supports typeof. + 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 */ \ + || (defined __SUNPRO_C && __SUNPRO_C >= 0x5110) /* C mode */ \ + || __STDC_VERSION__ >= 202311L /* C mode */ +# define HAVE_TYPEOF 1 +#endif + /* Whether the compiler supports __builtin_choose_expr. _Generic and __builtin_choose_expr are like conditional expressions, except that the return types of the branches need not match: They avoid an @@ -86,8 +98,8 @@ #endif /* Whether we support rw_string_desc_t as distinct from string_desc_t. */ -#if HAVE_STATEMENT_EXPRESSIONS && HAVE__GENERIC && HAVE_BUILTIN_CHOOSE_EXPR \ - && HAVE_BUILTIN_CONSTANT_P +#if HAVE_STATEMENT_EXPRESSIONS && HAVE__GENERIC && HAVE_TYPEOF \ + && HAVE_BUILTIN_CHOOSE_EXPR && HAVE_BUILTIN_CONSTANT_P # define HAVE_RW_STRING_DESC 1 #endif -- 2.52.0
