diff options
author | Martin Uecker <uecker@tugraz.at> | 2023-08-15 23:16:35 +0200 |
---|---|---|
committer | Martin Uecker <uecker@tugraz.at> | 2023-12-21 08:43:16 +0100 |
commit | ced651b7757e6ef7e7e309f022cd71b4b6ead295 (patch) | |
tree | ab0b4edd016dcb1f3942777bb3cc25c6f999e553 /gcc/c/c-parser.cc | |
parent | 23fee88f84873b0b8b41c8e5a9b229d533fb4022 (diff) | |
download | gcc-ced651b7757e6ef7e7e309f022cd71b4b6ead295.zip gcc-ced651b7757e6ef7e7e309f022cd71b4b6ead295.tar.gz gcc-ced651b7757e6ef7e7e309f022cd71b4b6ead295.tar.bz2 |
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.
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r-- | gcc/c/c-parser.cc | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index c372430..ed92cac 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -3667,6 +3667,7 @@ c_parser_enum_specifier (c_parser *parser) { struct c_typespec ret; bool have_std_attrs; + bool potential_nesting_p = false; tree std_attrs = NULL_TREE; tree attrs; tree ident = NULL_TREE; @@ -3706,6 +3707,7 @@ c_parser_enum_specifier (c_parser *parser) if (!ENUM_FIXED_UNDERLYING_TYPE_P (ret.spec)) error_at (enum_loc, "%<enum%> declared both with and without " "fixed underlying type"); + potential_nesting_p = NULL_TREE == TYPE_VALUES (ret.spec); } else { @@ -3776,7 +3778,8 @@ c_parser_enum_specifier (c_parser *parser) forward order at the end. */ tree values; timevar_push (TV_PARSE_ENUM); - type = start_enum (enum_loc, &the_enum, ident, fixed_underlying_type); + type = start_enum (enum_loc, &the_enum, ident, fixed_underlying_type, + potential_nesting_p); values = NULL_TREE; c_parser_consume_token (parser); while (true) |