diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2019-08-08 17:12:05 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2019-08-08 17:12:05 +0000 |
commit | 99769e7fb6ed153a53174b7f08415eee347655f0 (patch) | |
tree | b3462dfa470a06fd5cbee06fef2de8bf53ace907 /gcc/c | |
parent | 60bb944817d35ec0f01e5b78a5f248dabad8b7ca (diff) | |
download | gcc-99769e7fb6ed153a53174b7f08415eee347655f0.zip gcc-99769e7fb6ed153a53174b7f08415eee347655f0.tar.gz gcc-99769e7fb6ed153a53174b7f08415eee347655f0.tar.bz2 |
[C] Fix bogus nested enum error message
For:
enum a { A };
enum a { B };
we emit a bogus error about nested definitions before the real error:
foo.c:2:6: error: nested redefinition of ‘enum a’
2 | enum a { B };
| ^
foo.c:2:6: error: redeclaration of ‘enum a’
foo.c:1:6: note: originally defined here
1 | enum a { A };
| ^
This is because we weren't clearing C_TYPE_BEING_DEFINED once the
definition was over.
I think it's OK to clear C_TYPE_BEING_DEFINED even for a definition
that actually is nested (and so whose outer definition is still open),
since we'll already have given an error by then. It means that second
and subsequent attempts to define a nested enum will usually get the
redeclaration error instead of the nested error, but that seems just
as accurate (nested_first and nested_second in the test). The only
exception is if the first nested enum was also invalid by being empty,
but then the enum as a whole has already produced two errors
(nested_empty in the test).
2019-08-08 Richard Sandiford <richard.sandiford@arm.com>
gcc/c/
* c-decl.c (finish_enum): Clear C_TYPE_BEING_DEFINED.
gcc/testsuite/
* gcc.dg/pr79983.c (enum E): Don't allow an error about nested
definitions.
* gcc.dg/enum-redef-1.c: New test.
From-SVN: r274213
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 2 |
2 files changed, 6 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 4944696..533aebc 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,7 @@ +2019-08-08 Richard Sandiford <richard.sandiford@arm.com> + + * c-decl.c (finish_enum): Clear C_TYPE_BEING_DEFINED. + 2019-08-08 Jakub Jelinek <jakub@redhat.com> * c-typeck.c (c_finish_omp_clauses): For C_ORT_OMP diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index f85f481..9859cc7 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -8781,6 +8781,8 @@ finish_enum (tree enumtype, tree values, tree attributes) && !in_sizeof && !in_typeof && !in_alignof) struct_parse_info->struct_types.safe_push (enumtype); + C_TYPE_BEING_DEFINED (enumtype) = 0; + return enumtype; } |