From 99769e7fb6ed153a53174b7f08415eee347655f0 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Thu, 8 Aug 2019 17:12:05 +0000 Subject: [C] Fix bogus nested enum error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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/c-decl.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/c/c-decl.c') 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; } -- cgit v1.1