]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
stdcountof-h: Work around a clang bug.
authorBruno Haible <bruno@clisp.org>
Sun, 8 Jun 2025 00:58:21 +0000 (02:58 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 8 Jun 2025 01:02:12 +0000 (03:02 +0200)
Reported by Basil L. Contovounesios <basil@contovou.net> in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-06/msg00073.html>.

* lib/stdcountof.in.h (_gl_verify_is_array): Disable the checking on
clang.
* tests/test-stdcountof-h.c (test_func): Add another test case.

ChangeLog
lib/stdcountof.in.h
tests/test-stdcountof-h.c

index fedd5f64568aaf5cb20a6171a30d96ff9f13c9ed..ef6c6d19be18e5f91e78a7ec57fab6f10eb62dc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-06-07  Bruno Haible  <bruno@clisp.org>
+
+       stdcountof-h: Work around a clang bug.
+       Reported by Basil L. Contovounesios <basil@contovou.net> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2025-06/msg00073.html>.
+       * 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  <collin.funk1@gmail.com>
 
        doc: Add some missing Makefile targets.
index 105cf209a58cce632e2ee172a8272213a4d6bcbc..683b1c715622082a5f3b3a6fc0c2124f5d9da061 100644 (file)
@@ -81,7 +81,8 @@ template <typename T> _gl_array_type_test<T> _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 <https://github.com/llvm/llvm-project/issues/143284>.  */
+# 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
index cd7e03f3319c99fe16e36473fe0dc0e58b526d9f..5d0a9a66119932de562fe40dc377af496d645327 100644 (file)
@@ -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));