Hi! Here's the list of changes in v21:
- Drop patch 1 (I've sent it separately, as Joseph requested). - Keep Link tags. This means the other patch is an implicit dependency of this patch set. - Fix test compiler flags. [Joseph] - Add tests for <stdcountof.h>. [Joseph] - Add tests for pedantic diagnostics. [Joseph] I haven't compiled this, but since only tests changed since v20, it shouldn't fail. I haven't run `make check` for this revision (nor in v20). I will do both things in the following days. I've run the tests manually with a build of v20 I had, and they look good. Have a lovely day! Alex Alejandro Colomar (3): c: Add _Countof operator c: Add <stdcountof.h> c: Add -Wpedantic diagnostic for _Countof gcc/Makefile.in | 1 + gcc/c-family/c-common.cc | 26 +++ gcc/c-family/c-common.def | 3 + gcc/c-family/c-common.h | 2 + gcc/c/c-decl.cc | 22 ++- gcc/c/c-parser.cc | 63 +++++-- gcc/c/c-tree.h | 4 + gcc/c/c-typeck.cc | 115 ++++++++++++- gcc/doc/extend.texi | 30 ++++ gcc/ginclude/stdcountof.h | 31 ++++ gcc/testsuite/gcc.dg/countof-compat.c | 8 + gcc/testsuite/gcc.dg/countof-compile.c | 130 +++++++++++++++ gcc/testsuite/gcc.dg/countof-no-compat.c | 5 + .../gcc.dg/countof-pedantic-errors.c | 8 + gcc/testsuite/gcc.dg/countof-pedantic.c | 8 + gcc/testsuite/gcc.dg/countof-stdcountof.c | 21 +++ gcc/testsuite/gcc.dg/countof-vla.c | 51 ++++++ gcc/testsuite/gcc.dg/countof.c | 154 ++++++++++++++++++ 18 files changed, 658 insertions(+), 24 deletions(-) create mode 100644 gcc/ginclude/stdcountof.h create mode 100644 gcc/testsuite/gcc.dg/countof-compat.c create mode 100644 gcc/testsuite/gcc.dg/countof-compile.c create mode 100644 gcc/testsuite/gcc.dg/countof-no-compat.c create mode 100644 gcc/testsuite/gcc.dg/countof-pedantic-errors.c create mode 100644 gcc/testsuite/gcc.dg/countof-pedantic.c create mode 100644 gcc/testsuite/gcc.dg/countof-stdcountof.c create mode 100644 gcc/testsuite/gcc.dg/countof-vla.c create mode 100644 gcc/testsuite/gcc.dg/countof.c Range-diff against v20: 1: 0a752a02dd0 < -: ----------- contrib/: Add support for Link: tags 2: c28c880f609 ! 1: 432081a4747 c: Add _Countof operator @@ gcc/doc/extend.texi: library. ## gcc/testsuite/gcc.dg/countof-compile.c (new) ## @@ +/* { dg-do compile } */ -+/* { dg-options "-Wno-declaration-after-statement -Wno-pedantic -Wno-vla" } */ ++/* { dg-options "-std=c2y -pedantic-errors" } */ + +#define NULL ((void *) 0) + @@ gcc/testsuite/gcc.dg/countof-compile.c (new) ## gcc/testsuite/gcc.dg/countof-vla.c (new) ## @@ +/* { dg-do compile } */ -+/* { dg-options "-Wno-pedantic -Wvla-parameter" } */ ++/* { dg-options "-std=c2y -pedantic-errors -Wvla-parameter" } */ + +void fix_fix (int i, + char (*a)[3][5], @@ gcc/testsuite/gcc.dg/countof-vla.c (new) ## gcc/testsuite/gcc.dg/countof.c (new) ## @@ +/* { dg-do run } */ -+/* { dg-options "-Wno-declaration-after-statement -Wno-pedantic -Wno-vla" } */ ++/* { dg-options "-std=c2y -pedantic-errors" } */ + +#undef NDEBUG +#include <assert.h> 3: f6ff1f130de ! 2: 46294255dd8 c: Add <stdcountof.h> @@ Commit message * Makefile.in (USER_H): Add <stdcountof.h>. * ginclude/stdcountof.h: Add countof macro. + gcc/testsuite/ChangeLog: + + * gcc.dg/countof-stdcountof.c: Add tests for <stdcountof.h>. + Signed-off-by: Alejandro Colomar <a...@kernel.org> ## gcc/Makefile.in ## @@ gcc/ginclude/stdcountof.h (new) +#define countof _Countof + +#endif /* stdcountof.h */ + + ## gcc/testsuite/gcc.dg/countof-stdcountof.c (new) ## +@@ ++/* { dg-do run } */ ++/* { dg-options "-std=c2y -pedantic-errors" } */ ++ ++#include <stdcountof.h> ++ ++#ifndef countof ++#error "countof not defined" ++#endif ++ ++int a[3]; ++int b[countof a]; ++ ++#define str(x) #x ++#define xstr(x) str(x) ++ ++int ++main (void) ++{ ++ if (strcmp (xstr(countof), "_Alignas") != 0) ++ abort (); ++} 4: 94bc203a406 ! 3: 20cf2d14d3e c: Add -Wpedantic diagnostic for _Countof @@ Metadata ## Commit message ## c: Add -Wpedantic diagnostic for _Countof - It is not supported in <= C23 mode. + It has been standardized in C2y. gcc/c/ChangeLog: * c-parser.cc (c_parser_sizeof_or_countof_expression): Add -Wpedantic diagnostic for _Countof in <= C23 mode. + gcc/testsuite/ChangeLog: + + * gcc.dg/countof-compat.c + * gcc.dg/countof-no-compat.c + * gcc.dg/countof-pedantic.c + * gcc.dg/countof-pedantic-errors.c: + Test pedantic diagnostics for _Countof. + Signed-off-by: Alejandro Colomar <a...@kernel.org> ## gcc/c/c-parser.cc ## @@ gcc/c/c-parser.cc: c_parser_sizeof_or_countof_expression (c_parser *parser, enum c_parser_consume_token (parser); c_inhibit_evaluation_warnings++; if (rid == RID_COUNTOF) + + ## gcc/testsuite/gcc.dg/countof-compat.c (new) ## +@@ ++/* { dg-do compile } */ ++/* { dg-options "-std=c2y -pedantic-errors -Wc23-c2y-compat" } */ ++ ++#include <stdcountof.h> ++ ++int a[1]; ++int b[countof(a)]; ++int c[_Countof(a)]; /* { dg-warning "ISO C does not support" */ + + ## gcc/testsuite/gcc.dg/countof-no-compat.c (new) ## +@@ ++/* { dg-do compile } */ ++/* { dg-options "-std=c23 -pedantic-errors -Wno-c23-c2y-compat" } */ ++ ++int a[1]; ++int b[_Countof(a)]; + + ## gcc/testsuite/gcc.dg/countof-pedantic-errors.c (new) ## +@@ ++/* { dg-do compile } */ ++/* { dg-options "-std=c23 -pedantic-errors" } */ ++ ++#include <stdcountof.h> ++ ++int a[1]; ++int b[countof(a)]; ++int c[_Countof(a)]; /* { dg-error "ISO C does not support" */ + + ## gcc/testsuite/gcc.dg/countof-pedantic.c (new) ## +@@ ++/* { dg-do compile } */ ++/* { dg-options "-std=c23 -pedantic" } */ ++ ++#include <stdcountof.h> ++ ++int a[1]; ++int b[countof(a)]; ++int c[_Countof(a)]; /* { dg-warning "ISO C does not support" */ -- 2.49.0