]> git.ipfire.org Git - thirdparty/gcc.git/commit - gcc/c/ChangeLog
[C] Fix bogus nested enum error message
authorRichard Sandiford <richard.sandiford@arm.com>
Thu, 8 Aug 2019 17:12:05 +0000 (17:12 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Thu, 8 Aug 2019 17:12:05 +0000 (17:12 +0000)
commit99769e7fb6ed153a53174b7f08415eee347655f0
treeb3462dfa470a06fd5cbee06fef2de8bf53ace907
parent60bb944817d35ec0f01e5b78a5f248dabad8b7ca
[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
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/enum-redef-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr79983.c