On 8/5/19 3:00 AM, Richard Sandiford wrote:
> 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).
>
> Tested on aarch64-linux-gnu, armeb-eabi and x86_64-linux-gnu.
> OK to install?
>
> Richard
>
>
> 2019-08-05 Richard Sandiford <richard.sandif...@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.
OK
jeff