On 2025-06-07 I added this:
> 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));
> 

But this leads to a link error on MSVC 14. This patch fixes it.


2025-10-12  Bruno Haible  <[email protected]>

        stdcountof-h tests: Fix link error on MSVC 14 (regression 2025-06-07).
        * tests/test-stdcountof-h.c (a, b, c): Define as variables on MSVC.

diff --git a/tests/test-stdcountof-h.c b/tests/test-stdcountof-h.c
index 77cfbc4dec..615cccda16 100644
--- a/tests/test-stdcountof-h.c
+++ b/tests/test-stdcountof-h.c
@@ -105,3 +105,12 @@ main ()
 
   return test_exit_status;
 }
+
+/* A definition of the variables a, b, c is not required by ISO C, because
+   these identifiers are only used as part of 'sizeof' expressions whose
+   results are integer expressions.  See ISO C 23 ยง 6.9.1.(5).  However,
+   MSVC 14 generates actual references to these variables.  We thus need
+   to define these variables; otherwise we get link errors.  */
+#if defined _MSC_VER && !defined __clang__
+int a, b, c;
+#endif




Reply via email to