Hash :
49c5d4bc
Author :
Date :
2025-09-08T13:42:54
stdcountof-h tests: Fix compilation error with clang 21. * tests/test-stdcountof-h.c (test_func): Don't use _gl_verify_is_array if it's not defined.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/* Test <stdcountof.h>.
Copyright 2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#include <stdcountof.h>
#include "macros.h"
/* Whether the compiler supports _Generic.
Test program:
int f (int x) { return _Generic (x, char *: 2, int: 3); }
*/
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 9) > 4) \
|| (defined __clang__ && __clang_major__ >= 3) \
|| (defined __SUNPRO_C && __SUNPRO_C >= 0x5150)
# define HAVE__GENERIC 1
#endif
extern int integer;
extern int unbounded[];
extern int bounded[10];
extern int multidimensional[10][20];
static void
test_func (int parameter[3])
{
int local_bounded[20];
(void) local_bounded;
#ifdef _gl_verify_is_array
(void) _gl_verify_is_array (unbounded);
(void) _gl_verify_is_array (bounded);
(void) _gl_verify_is_array (multidimensional);
#endif
ASSERT (countof (bounded) == 10);
ASSERT (countof (multidimensional) == 10);
ASSERT (countof (local_bounded) == 20);
#if 0 /* These produce compilation errors. */
# ifdef _gl_verify_is_array
(void) _gl_verify_is_array (integer);
(void) _gl_verify_is_array (parameter);
# endif
ASSERT (countof (integer) >= 0);
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));
ASSERT (_Generic (countof (multidimensional), size_t: 1, default: 0));
ASSERT (_Generic (countof (local_bounded), size_t: 1, default: 0));
#endif
}
int
main ()
{
int x[3];
test_func (x);
return test_exit_status;
}