r274213 - in /trunk/gcc: c/ChangeLog c/c-decl.c...

rsandifo@gcc.gnu.org rsandifo@gcc.gnu.org
Thu Aug 8 17:12:00 GMT 2019


Author: rsandifo
Date: Thu Aug  8 17:12:05 2019
New Revision: 274213

URL: https://gcc.gnu.org/viewcvs?rev=274213&root=gcc&view=rev
Log:
[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.

Added:
    trunk/gcc/testsuite/gcc.dg/enum-redef-1.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/pr79983.c



More information about the Gcc-cvs mailing list