Hi! Here's v25. Changes compared to v24 (see range-diff below):
- Small fixes to the change logs. - Rewrap and remove parentheses in chains of ?: . - Implement c_parser_{sizeof,countof}_expression() as static inline. Tests still pass: $ grep countof ./gcc/testsuite/gcc/gcc.sum PASS: gcc.dg/countof-compat.c (test for warnings, line 8) PASS: gcc.dg/countof-compat.c (test for excess errors) PASS: gcc.dg/countof-compile.c (test for errors, line 114) PASS: gcc.dg/countof-compile.c (test for errors, line 123) PASS: gcc.dg/countof-compile.c (test for errors, line 23) PASS: gcc.dg/countof-compile.c (test for errors, line 27) PASS: gcc.dg/countof-compile.c (test for errors, line 38) PASS: gcc.dg/countof-compile.c (test for errors, line 46) PASS: gcc.dg/countof-compile.c (test for errors, line 64) PASS: gcc.dg/countof-compile.c (test for errors, line 67) PASS: gcc.dg/countof-compile.c (test for errors, line 70) PASS: gcc.dg/countof-compile.c (test for errors, line 82) PASS: gcc.dg/countof-compile.c (test for errors, line 83) PASS: gcc.dg/countof-compile.c (test for errors, line 84) PASS: gcc.dg/countof-compile.c (test for errors, line 85) PASS: gcc.dg/countof-compile.c (test for errors, line 86) PASS: gcc.dg/countof-compile.c (test for errors, line 87) PASS: gcc.dg/countof-compile.c (test for errors, line 88) PASS: gcc.dg/countof-compile.c (test for errors, line 89) PASS: gcc.dg/countof-compile.c (test for errors, line 90) PASS: gcc.dg/countof-compile.c (test for errors, line 94) PASS: gcc.dg/countof-compile.c (test for excess errors) PASS: gcc.dg/countof-no-compat.c (test for excess errors) PASS: gcc.dg/countof-pedantic-errors.c (test for errors, line 8) PASS: gcc.dg/countof-pedantic-errors.c (test for excess errors) PASS: gcc.dg/countof-pedantic.c (test for warnings, line 8) PASS: gcc.dg/countof-pedantic.c (test for excess errors) PASS: gcc.dg/countof-stdcountof.c (test for excess errors) PASS: gcc.dg/countof-stdcountof.c execution test PASS: gcc.dg/countof-vla.c (test for excess errors) PASS: gcc.dg/countof-vmt.c (test for excess errors) PASS: gcc.dg/countof-vmt.c execution test PASS: gcc.dg/countof-zero-compile.c (test for excess errors) PASS: gcc.dg/countof-zero.c (test for excess errors) PASS: gcc.dg/countof-zero.c execution test PASS: gcc.dg/countof.c (test for excess errors) PASS: gcc.dg/countof.c execution test Have a lovely night! 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 | 24 ++-- gcc/c/c-parser.cc | 77 ++++++++--- 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 | 124 ++++++++++++++++++ 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 | 24 ++++ gcc/testsuite/gcc.dg/countof-vla.c | 35 +++++ gcc/testsuite/gcc.dg/countof-vmt.c | 20 +++ gcc/testsuite/gcc.dg/countof-zero-compile.c | 38 ++++++ gcc/testsuite/gcc.dg/countof-zero.c | 31 +++++ gcc/testsuite/gcc.dg/countof.c | 120 +++++++++++++++++ 21 files changed, 705 insertions(+), 29 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-vmt.c create mode 100644 gcc/testsuite/gcc.dg/countof-zero-compile.c create mode 100644 gcc/testsuite/gcc.dg/countof-zero.c create mode 100644 gcc/testsuite/gcc.dg/countof.c Range-diff against v24: 1: 1ac81ab0d3dc ! 1: a3fb6089a388 c: Add _Countof operator @@ Commit message gcc/c-family/ChangeLog: - * c-common.h: Add RID_COUNTOF. + * c-common.h (enum rid): Add RID_COUNTOF. (c_countof_type): New function prototype. * c-common.def (COUNTOF_EXPR): New tree. - * c-common.cc - (c_common_reswords): Add RID_COUNTOF entry. + * c-common.cc (c_common_reswords): Add RID_COUNTOF entry. (c_countof_type): New function. gcc/c/ChangeLog: - * c-tree.h - (in_countof): Add global variable declaration. + * c-tree.h (in_countof): Add global variable declaration. (c_expr_countof_expr): Add function prototype. (c_expr_countof_type): Add function prototype. - * c-decl.cc - (start_struct, finish_struct): Add support for _Countof. + * c-decl.cc (start_struct, finish_struct): Add support for + _Countof. (start_enum, finish_enum): Add support for _Countof. - * c-parser.cc - (c_parser_sizeof_expression): New macro. + * c-parser.cc (c_parser_sizeof_expression): New macro. (c_parser_countof_expression): New macro. - (c_parser_sizeof_or_countof_expression): - Rename function and add support for _Countof. + (c_parser_sizeof_or_countof_expression): Rename function and add + support for _Countof. (c_parser_unary_expression): Add RID_COUNTOF entry. - * c-typeck.cc - (in_countof): Add global variable. + * c-typeck.cc (in_countof): Add global variable. (build_external_ref): Add support for _Countof. (record_maybe_used_decl): Add support for _Countof. (pop_maybe_used): Add support for _Countof. (is_top_array_vla): New function. (c_expr_countof_expr, c_expr_countof_type): New functions. - Add _Countof operator. gcc/testsuite/ChangeLog: - * gcc.dg/countof-compile.c: Compile-time tests for _Countof. - * gcc.dg/countof-vla.c: Tests for _Countof with VLAs. - * gcc.dg/countof-vmt.c: Tests for _Countof with other VMTs. - * gcc.dg/countof-zero-compile.c: - Compile-time tests for _Countof with zero-sized arrays. - * gcc.dg/countof-zero.c: - Tests for _Countof with zero-sized arrays. - * gcc.dg/countof.c: Tests for _Countof. + * gcc.dg/countof-compile.c: New test. + * gcc.dg/countof-vla.c: New test. + * gcc.dg/countof-vmt.c: New test. + * gcc.dg/countof-zero-compile.c: New test. + * gcc.dg/countof-zero.c: New test. + * gcc.dg/countof.c: New test. Suggested-by: Xavier Del Campo Romero <xavi....@tutanota.com> Co-authored-by: Martin Uecker <uec...@tugraz.at> @@ gcc/c/c-decl.cc: start_struct (location_t loc, enum tree_code code, tree name, + && (in_sizeof || in_typeof || in_alignof || in_countof)) warning_at (loc, OPT_Wc___compat, "defining type in %qs expression is invalid in C++", - (in_sizeof - ? "sizeof" +- (in_sizeof +- ? "sizeof" - : (in_typeof ? "typeof" : "alignof"))); -+ : (in_typeof -+ ? "typeof" -+ : (in_alignof -+ ? "alignof" -+ : "_Countof")))); ++ (in_sizeof ? "sizeof" ++ : in_typeof ? "typeof" ++ : in_alignof ? "alignof" ++ : "_Countof")); if (in_underspecified_init) error_at (loc, "%qT defined in underspecified object initializer", ref); @@ gcc/c/c-decl.cc: start_enum (location_t loc, struct c_enum_contents *the_enum, t + && (in_sizeof || in_typeof || in_alignof || in_countof)) warning_at (loc, OPT_Wc___compat, "defining type in %qs expression is invalid in C++", - (in_sizeof - ? "sizeof" +- (in_sizeof +- ? "sizeof" - : (in_typeof ? "typeof" : "alignof"))); -+ : (in_typeof -+ ? "typeof" -+ : (in_alignof -+ ? "alignof" -+ : "_Countof")))); ++ (in_sizeof ? "sizeof" ++ : in_typeof ? "typeof" ++ : in_alignof ? "alignof" ++ : "_Countof")); if (in_underspecified_init) error_at (loc, "%qT defined in underspecified object initializer", @@ gcc/c/c-parser.cc: along with GCC; see the file COPYING3. If not see #include "asan.h" #include "c-family/c-ubsan.h" #include "gcc-urlifier.h" -+ -+#define c_parser_sizeof_expression(parser) \ -+( \ -+ c_parser_sizeof_or_countof_expression (parser, RID_SIZEOF) \ -+) - -+#define c_parser_countof_expression(parser) \ -+( \ -+ c_parser_sizeof_or_countof_expression (parser, RID_COUNTOF) \ -+) +- + /* We need to walk over decls with incomplete struct/union/enum types after parsing the whole translation unit. @@ gcc/c/c-parser.cc: static struct c_expr c_parser_binary_expression (c_parser *, static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); static struct c_expr c_parser_unary_expression (c_parser *); -static struct c_expr c_parser_sizeof_expression (c_parser *); ++static inline struct c_expr c_parser_sizeof_expression (c_parser *); ++static inline struct c_expr c_parser_countof_expression (c_parser *); +static struct c_expr c_parser_sizeof_or_countof_expression (c_parser *, + enum rid); static struct c_expr c_parser_alignof_expression (c_parser *); @@ gcc/c/c-parser.cc: c_parser_unary_expression (c_parser *parser) return c_parser_sizeof_expression (parser); case RID_ALIGNOF: @@ gcc/c/c-parser.cc: c_parser_unary_expression (c_parser *parser) + /* Parse a sizeof expression. */ - static struct c_expr --c_parser_sizeof_expression (c_parser *parser) -+c_parser_sizeof_or_countof_expression (c_parser *parser, enum rid rid) +-static struct c_expr ++static inline struct c_expr + c_parser_sizeof_expression (c_parser *parser) { ++ return c_parser_sizeof_or_countof_expression (parser, RID_SIZEOF); ++} ++ ++/* Parse a _Countof expression. */ ++ ++static inline struct c_expr ++c_parser_countof_expression (c_parser *parser) ++{ ++ return c_parser_sizeof_or_countof_expression (parser, RID_COUNTOF); ++} ++ ++/* Parse a sizeof or _Countof expression. */ ++ ++static struct c_expr ++c_parser_sizeof_or_countof_expression (c_parser *parser, enum rid rid) ++{ + const char *op_name = (rid == RID_COUNTOF) ? "_Countof" : "sizeof"; struct c_expr expr; struct c_expr result; 2: b9e8bed2de2b ! 2: bad376570c9a c: Add <stdcountof.h> @@ Commit message gcc/ChangeLog: * Makefile.in (USER_H): Add <stdcountof.h>. - * ginclude/stdcountof.h: Add countof macro. + * ginclude/stdcountof.h: New file. gcc/testsuite/ChangeLog: - * gcc.dg/countof-stdcountof.c: Add tests for <stdcountof.h>. + * gcc.dg/countof-stdcountof.c: New test. Signed-off-by: Alejandro Colomar <a...@kernel.org> 3: 264c87d60157 ! 3: 85de63d37f8d c: Add -Wpedantic diagnostic for _Countof @@ Commit message gcc/testsuite/ChangeLog: - * gcc.dg/countof-compat.c: - Test _Countof diagnostics with -Wc23-c2y-compat on C2y. - * gcc.dg/countof-no-compat.c: - Test _Countof diagnostics with -Wno-c23-c2y-compat on C23. - * gcc.dg/countof-pedantic.c: - Test _Countof diagnostics with -pedantic on C23. - * gcc.dg/countof-pedantic-errors.c: - Test _Countof diagnostics with -pedantic-errors on C23. + * 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 <a...@kernel.org> base-commit: 90c6ccebd762ae920690fce20cd3f2b8e24357a7 -- 2.49.0