It has been standardized in C2y.
PR c/117025
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: New test.
* gcc.dg/countof-no-compat.c: New test.
* gcc.dg/countof-pedantic.c: New test.
* gcc.dg/countof-pedantic-errors.c: New test.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
start = c_parser_peek_token (parser)->location;
+ if (rid == RID_COUNTOF)
+ pedwarn_c23 (start, OPT_Wpedantic,
+ "ISO C does not support %qs before C23", op_name);
+
c_parser_consume_token (parser);
c_inhibit_evaluation_warnings++;
if (rid == RID_COUNTOF)
--- /dev/null
+/* { 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" } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic-errors -Wno-c23-c2y-compat" } */
+
+int a[1];
+int b[_Countof(a)];
--- /dev/null
+/* { 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" } */
--- /dev/null
+/* { 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" } */