Paul Eggert wrote:
> diff --git a/tests/test-stdcountof-h.c b/tests/test-stdcountof-h.c
> index 0b4c4cc15f..191ba5c779 100644
> --- a/tests/test-stdcountof-h.c
> +++ b/tests/test-stdcountof-h.c
> @@ -78,11 +78,8 @@ test_func (int parameter[3])
> ASSERT (countof (unbounded) >= 0);
> #endif
>
> - {
> - extern int a, b, c;
> - ASSERT (countof ((int[]) { a, b, c }) == 3);
> - ASSERT (countof (((int[]) { a, b, c })) == 3);
> - }
> + ASSERT (countof ((int[]) { integer, integer, integer }) == 3);
> + ASSERT (countof (((int[]) { integer, integer, integer })) == 3);
>
> /* Check that countof(...) is an expression of type size_t. */
> #if !defined __cplusplus && HAVE__GENERIC
Unfortunately, this causes a link error with MSVC. This is because
the variables a, b, c are defined at the end of the file, whereas 'integer'
is not.
I'm applying this fix:
2026-01-15 Bruno Haible <[email protected]>
stdcountof-h tests: Fix link error on MSVC (regression 2026-01-13).
* tests/test-stdcountof-h.c: Revert 2026-01-13 change. Instead:
(a, b, c): Declare extern at top level.
diff --git a/tests/test-stdcountof-h.c b/tests/test-stdcountof-h.c
index 03498ae99d..07a86fef98 100644
--- a/tests/test-stdcountof-h.c
+++ b/tests/test-stdcountof-h.c
@@ -34,6 +34,7 @@ extern int integer;
extern int unbounded[];
extern int bounded[10];
extern int multidimensional[10][20];
+extern int a, b, c;
static void
test_func (int parameter[3])
@@ -81,8 +82,8 @@ test_func (int parameter[3])
/* Avoid MSVC C++ error C4576 "a parenthesized type followed by an
initializer list is a non-standard explicit type conversion syntax". */
#if !defined __cplusplus
- ASSERT (countof ((int[]) { integer, integer, integer }) == 3);
- ASSERT (countof (((int[]) { integer, integer, integer })) == 3);
+ ASSERT (countof ((int[]) { a, b, c }) == 3);
+ ASSERT (countof (((int[]) { a, b, c })) == 3);
#endif
/* Check that countof(...) is an expression of type size_t. */