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.

For readability of some weird code, or in the case of C code generated by other 
tools.

By the way, gcc version 12.2.0 (Debian 12.2.0-14) don't emit any warnings 
neither when used on your example as gcc -Wall -Wextra -fanalyzer /tmp/andrea.c 
-o /tmp/andrea

If you really want to get warnings, consider writing your GCC plugin (perhaps 
starting with https://github.com/bstarynk/bismon/ ....) or using static 
analysis tools like https://frama-c.com/

Regards.

NB my pet open source project is the RefPerSys open source inference engine 
(work in progress) on http://refpersys.org/

--
Basile Starynkevitch <bas...@starynkevitch.net>
92340 Bourg-la-Reine, France
http://starynkevitch.net/Basile/ and http://refpersys.org/

Reply via email to