From: Bruno Haible Date: Sun, 8 Jun 2025 00:58:21 +0000 (+0200) Subject: stdcountof-h: Work around a clang bug. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd6bd646350a1bf914701c199194ae4522bb7ca5;p=thirdparty%2Fgnulib.git stdcountof-h: Work around a clang bug. Reported by Basil L. Contovounesios in . * lib/stdcountof.in.h (_gl_verify_is_array): Disable the checking on clang. * tests/test-stdcountof-h.c (test_func): Add another test case. --- diff --git a/ChangeLog b/ChangeLog index fedd5f6456..ef6c6d19be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2025-06-07 Bruno Haible + + stdcountof-h: Work around a clang bug. + Reported by Basil L. Contovounesios in + . + * lib/stdcountof.in.h (_gl_verify_is_array): Disable the checking on + clang. + * tests/test-stdcountof-h.c (test_func): Add another test case. + 2025-06-06 Collin Funk doc: Add some missing Makefile targets. diff --git a/lib/stdcountof.in.h b/lib/stdcountof.in.h index 105cf209a5..683b1c7156 100644 --- a/lib/stdcountof.in.h +++ b/lib/stdcountof.in.h @@ -81,7 +81,8 @@ template _gl_array_type_test _gl_array_type_test_helper(T&); # endif #else /* In C, we can use typeof and __builtin_types_compatible_p. */ -# if _GL_GNUC_PREREQ (3, 1) || defined __clang__ +/* Work around clang bug . */ +# if _GL_GNUC_PREREQ (3, 1) && ! defined __clang__ /* || defined __clang__ */ # define _gl_verify_is_array(a) \ sizeof (struct { unsigned int _gl_verify_error_if_negative : __builtin_types_compatible_p (typeof (a), typeof (&*(a))) ? -1 : 1; }) # else diff --git a/tests/test-stdcountof-h.c b/tests/test-stdcountof-h.c index cd7e03f331..5d0a9a6611 100644 --- a/tests/test-stdcountof-h.c +++ b/tests/test-stdcountof-h.c @@ -58,6 +58,11 @@ test_func (int parameter[3]) ASSERT (countof (unbounded) >= 0); #endif + { + extern int a, b, c; + ASSERT (countof (((int[]) { a, b, c })) == 3); + } + /* Check that countof(...) is an expression of type size_t. */ #if !defined __cplusplus && HAVE__GENERIC ASSERT (_Generic (countof (bounded), size_t: 1, default: 0));