On 3/13/23 14:29, Marek Polacek wrote:
On Sat, Mar 11, 2023 at 04:48:14PM +0000, Jonathan Wakely via Gcc wrote:
On Sat, 11 Mar 2023, 12:53 Basile Starynkevitch, <bas...@starynkevitch.net>
wrote:

Hello all,


Andrea observed that:

In gcc 8.3.0, compiling


enum
test
    {
      FIRST = 1,
      SECOND = 1,
      THIRD = 2
    };

int
main (void)
{
    return 0;
}


generates no warning even with -Wextra.

I believe that the C standard (which I don't have here, but see also
https://port70.net/~nsz/c/c11/n1570.html or buy it from ISO) explicitly
allow duplicate values in enum.


Of course it does, it's perfectly valid. Nobody has said it should be
rejected. The request is for a warning, because for *some* uses of enums
duplicates are not wanted.
And as I said in the other thread about the very same issue, it's
<https://gcc.gnu.org/PR16186> which is assigned to me and I hope to
implement it for GCC 14.

Marek


Then consider perhaps:

prototyping that warning in your own GCC plugin (and test it on a bunch of existing open source software).

adding some explicit new warning option to enable that new warning or adding another option to disable that warning in a compilation unit.

adding some explicit #pragma to disable that new warning (with the hope that tools generating C++ code would later -in 2024- emit the pragma appropriately)

Since there are some valid, probably weird, cases (notably generated C++ code, or low level driver code where two different enum names need to share some common values, ....) where having duplicate values in enum may make sense.

Regards

--
Basile Starynkevitch                  <bas...@starynkevitch.net>
(only mine opinions / les opinions sont miennes uniquement)
92340 Bourg-la-Reine, France
web page: starynkevitch.net/Basile/ & refpersys.org

Reply via email to