public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107164] New: No pedantic warning for declaration just referring to a previously-declared enum type
@ 2022-10-05 21:57 stephenheumann at gmail dot com
  2022-10-05 22:05 ` [Bug c/107164] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: stephenheumann at gmail dot com @ 2022-10-05 21:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107164

            Bug ID: 107164
           Summary: No pedantic warning for declaration just referring to
                    a previously-declared enum type
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stephenheumann at gmail dot com
  Target Milestone: ---

gcc -std=c17 -pedantic accepts this without any diagnostics:

enum E {a,b,c};
enum E;

C17 section 6.7.2.3 p9 says that an "enum identifier" type specifier using a
tag with an existing declaration visible "specifies the same type as that other
declaration, and does not redeclare the tag". Accordingly, the second line
above does not declare a declarator, a tag, or the members of an enumeration,
and so it violates the constraint in C17 section 6.7 p2.

(The relevant standard text is basically the same from C99 through draft C23.
C90 is less explicit, but I think is intended to behave the same.)

This should at least give a pedantic warning. Perhaps it could be an
always-enabled warning, but I'm not sure if code like the above is supposed to
be allowed as a GCC extension.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/107164] No pedantic warning for declaration just referring to a previously-declared enum type
  2022-10-05 21:57 [Bug c/107164] New: No pedantic warning for declaration just referring to a previously-declared enum type stephenheumann at gmail dot com
@ 2022-10-05 22:05 ` pinskia at gcc dot gnu.org
  2022-10-18 23:26 ` cvs-commit at gcc dot gnu.org
  2022-10-18 23:27 ` jsm28 at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-05 22:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107164

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang says it is a GCC extension:
<source>:2:6: warning: redeclaration of already-defined enum 'E' is a GNU
extension [-Wgnu-redeclared-enum]
enum E;
     ^
<source>:1:6: note: previous definition is here
enum E {a,b,c};
     ^

GCC does have a forward declaration extension for enum types so it makes sense
to allow this as an extension too.

That is:
```
enum E;
enum E {a,b,c};
```

(which GCC does have a pedantic diagnostic about).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/107164] No pedantic warning for declaration just referring to a previously-declared enum type
  2022-10-05 21:57 [Bug c/107164] New: No pedantic warning for declaration just referring to a previously-declared enum type stephenheumann at gmail dot com
  2022-10-05 22:05 ` [Bug c/107164] " pinskia at gcc dot gnu.org
@ 2022-10-18 23:26 ` cvs-commit at gcc dot gnu.org
  2022-10-18 23:27 ` jsm28 at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-10-18 23:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107164

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Joseph Myers <jsm28@gcc.gnu.org>:

https://gcc.gnu.org/g:f5f1d92fe2e1d75c3fae34497929a1965af704ae

commit r13-3366-gf5f1d92fe2e1d75c3fae34497929a1965af704ae
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Tue Oct 18 23:25:47 2022 +0000

    c: Diagnose "enum tag;" after definition [PR107164]

    As noted in bug 101764, a declaration "enum tag;" is invalid in
    standard C after a definition, as well as when no definition is
    visible; we had a pedwarn-if-pedantic for the forward declaration
    case, but were missing one for the other case.  Add that missing
    diagnostic (if pedantic only).

    (These diagnostics will need to be appropriately conditioned when
    support is added for C2x enums with fixed underlying type, since "enum
    tag : type;" is OK both before and after a definition.)

    Bootstrapped with no regressions for x86_64-pc-linux-gnu.

            PR c/107164

    gcc/c/
            * c-decl.cc (shadow_tag_warned): If pedantic, diagnose "enum tag;"
            with previous declaration visible.

    gcc/testsuite/
            * gcc.dg/c99-tag-4.c, gcc.dg/c99-tag-5.c, gcc.dg/c99-tag-6.c: New
            tests.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/107164] No pedantic warning for declaration just referring to a previously-declared enum type
  2022-10-05 21:57 [Bug c/107164] New: No pedantic warning for declaration just referring to a previously-declared enum type stephenheumann at gmail dot com
  2022-10-05 22:05 ` [Bug c/107164] " pinskia at gcc dot gnu.org
  2022-10-18 23:26 ` cvs-commit at gcc dot gnu.org
@ 2022-10-18 23:27 ` jsm28 at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2022-10-18 23:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107164

Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
Fixed for GCC 13.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-18 23:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-05 21:57 [Bug c/107164] New: No pedantic warning for declaration just referring to a previously-declared enum type stephenheumann at gmail dot com
2022-10-05 22:05 ` [Bug c/107164] " pinskia at gcc dot gnu.org
2022-10-18 23:26 ` cvs-commit at gcc dot gnu.org
2022-10-18 23:27 ` jsm28 at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).