Hi Joseph, On Fri, May 16, 2025 at 12:25:39PM +0000, Joseph Myers wrote: > On Fri, 16 May 2025, Alejandro Colomar wrote: > > > - Add <assert.h> (and NDEBUG) to some test files that were missing it, > > and also the forward declaration of strcmp(3). > > Depending on libc headers like this in tests is discouraged. The usual > idiom is to use abort () on failure of a runtime check (rather than > assert) and to declare abort in the test (or use __builtin_abort to avoid > needing the declaration).
Hmmm, I've been trying to find a compromise between readability and simplicity, and I think I have something. I've seen some tests that define assert() themselves. I like assert(3) because it's more readable compared to a conditional plus abort(3). So, how do you feel about the following change? diff --git i/gcc/testsuite/gcc.dg/countof-stdcountof.c w/gcc/testsuite/gcc.dg/countof-stdcountof.c index a7fe4079c69..2fb0c6306ef 100644 --- i/gcc/testsuite/gcc.dg/countof-stdcountof.c +++ w/gcc/testsuite/gcc.dg/countof-stdcountof.c @@ -3,8 +3,7 @@ #include <stdcountof.h> -#undef NDEBUG -#include <assert.h> +#define assert(e) ((e) ? (void) 0 : __builtin_abort ()) extern int strcmp (const char *, const char *); diff --git i/gcc/testsuite/gcc.dg/countof-vmt.c w/gcc/testsuite/gcc.dg/countof-vmt.c index f84d5aa618d..cf4bfd1aa74 100644 --- i/gcc/testsuite/gcc.dg/countof-vmt.c +++ w/gcc/testsuite/gcc.dg/countof-vmt.c @@ -1,8 +1,7 @@ /* { dg-do run } */ /* { dg-options "-std=c2y" } */ -#undef NDEBUG -#include <assert.h> +#define assert(e) ((e) ? (void) 0 : __builtin_abort ()) void inner_vla_noeval (void) diff --git i/gcc/testsuite/gcc.dg/countof-zero.c w/gcc/testsuite/gcc.dg/countof-zero.c index 07dfc2bfbf2..678a08148a5 100644 --- i/gcc/testsuite/gcc.dg/countof-zero.c +++ w/gcc/testsuite/gcc.dg/countof-zero.c @@ -1,8 +1,7 @@ /* { dg-do run } */ /* { dg-options "-std=c2y" } */ -#undef NDEBUG -#include <assert.h> +#define assert(e) ((e) ? (void) 0 : __builtin_abort ()) void vla (void) diff --git i/gcc/testsuite/gcc.dg/countof.c w/gcc/testsuite/gcc.dg/countof.c index 15ed7719100..534488501c6 100644 --- i/gcc/testsuite/gcc.dg/countof.c +++ w/gcc/testsuite/gcc.dg/countof.c @@ -1,8 +1,7 @@ /* { dg-do run } */ /* { dg-options "-std=c2y -pedantic-errors" } */ -#undef NDEBUG -#include <assert.h> +#define assert(e) ((e) ? (void) 0 : __builtin_abort ()) void array (void) Have a lovely day! Alex -- <https://www.alejandro-colomar.es/>
signature.asc
Description: PGP signature