From: Bruno Haible Date: Wed, 8 Oct 2025 12:10:13 +0000 (+0200) Subject: stdcountof-h: Add support for string literal arguments in C++ mode. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5124e917b1b2304f5ca2b72e2575a00af8b198ca;p=thirdparty%2Fgnulib.git stdcountof-h: Add support for string literal arguments in C++ mode. Reported by Alejandro Colomar in . * lib/stdcountof.in.h (_gl_array_type_test): Add a partial instantiation for string literals. --- diff --git a/ChangeLog b/ChangeLog index b8f98a18ae..2fa327c5d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2025-10-08 Bruno Haible + + stdcountof-h: Add support for string literal arguments in C++ mode. + Reported by Alejandro Colomar in + . + * lib/stdcountof.in.h (_gl_array_type_test): Add a partial instantiation + for string literals. + 2025-10-03 Bruno Haible localename-unsafe: Fix handling of yue-Hans locale on macOS. diff --git a/lib/stdcountof.in.h b/lib/stdcountof.in.h index 93c7f6bb75..6e602b4a9f 100644 --- a/lib/stdcountof.in.h +++ b/lib/stdcountof.in.h @@ -72,11 +72,15 @@ template /* Bounded arrays. */ template struct _gl_array_type_test { static const int is_array = 1; }; +/* String literals. */ +template + struct _gl_array_type_test { static const int is_array = 1; }; # define _gl_verify_is_array(a) \ sizeof (_gl_verify_type<_gl_array_type_test::is_array>) # else /* Use template argument deduction. - Use sizeof to get a constant expression from an unknown type. */ + Use sizeof to get a constant expression from an unknown type. + Note: This approach does not work for countof (((int[]) { a, b, c })). */ /* Default case. */ template struct _gl_array_type_test { double large; };