[Bug c/16186] gcc should have an option to warn about enumerations with duplicate values
mpolacek at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Oct 24 18:37:05 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16186
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
FWIW, Clang implements this warning:
$ xclang++ -c -xc j.c -Wduplicate-enum
j.c:1:33: warning: element 'foo' has been implicitly assigned 0 which another
element has been assigned [-Wduplicate-enum]
enum status { ok = 0, err = -1, foo, bar };
^~~
j.c:1:15: note: element 'ok' also has value 0
enum status { ok = 0, err = -1, foo, bar };
^~~~~~
I suppose we could do a binary search when adding a new enumerator in
build_enumerator, see if an enumerator with the same value is already present,
and warn if so.
More information about the Gcc-bugs
mailing list