From ced651b7757e6ef7e7e309f022cd71b4b6ead295 Mon Sep 17 00:00:00 2001 From: Martin Uecker Date: Tue, 15 Aug 2023 23:16:35 +0200 Subject: c23: tag compatibility rules for enums Allow redefinition of enum types and enumerators. Diagnose nested redefinitions including redefinitions in the enum specifier for enum types with fixed underlying type. gcc/c: * c-tree.h (c_parser_enum_specifier): Add parameter. * c-decl.cc (start_enum): Allow redefinition. (finish_enum): Diagnose conflicts. (build_enumerator): Set context. (diagnose_mismatched_decls): Diagnose conflicting enumerators. (push_decl): Preserve context for enumerators. * c-typeck.cc (tagged_types_tu_compatible_p): Adapt. * c-parser.cc (c_parser_enum_specifier): Remember when seen is from an enum type which is not yet defined. gcc/testsuite: * gcc.dg/c23-tag-enum-1.c: New test. * gcc.dg/c23-tag-enum-2.c: New test. * gcc.dg/c23-tag-enum-3.c: New test. * gcc.dg/c23-tag-enum-4.c: New test. * gcc.dg/c23-tag-enum-5.c: New test. * gcc.dg/gnu23-tag-enum-1.c: Mew test. --- gcc/c/c-tree.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gcc/c/c-tree.h') diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index e53948f..54f1353 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -683,7 +683,8 @@ extern void c_warn_unused_attributes (tree); extern tree c_warn_type_attributes (tree); extern void shadow_tag (const struct c_declspecs *); extern void shadow_tag_warned (const struct c_declspecs *, int); -extern tree start_enum (location_t, struct c_enum_contents *, tree, tree); +extern tree start_enum (location_t, struct c_enum_contents *, tree, tree, + bool potential_nesting_p); extern bool start_function (struct c_declspecs *, struct c_declarator *, tree); extern tree start_decl (struct c_declarator *, struct c_declspecs *, bool, tree, bool = true, location_t * = NULL); -- cgit v1.1