From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7093F3858421; Mon, 24 Oct 2022 18:37:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7093F3858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666636626; bh=0P54pHhRn2sKgBqik86ECmcKrZQ7HFRKFSJ+SVfhRA4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=w9mL0czFB8a4Yj0RAkTxzF1hzOXczD30T8cXRAbdHy9HGh/woR/HswPGteBc3u2a3 CtIWZFeQyxp5mvniaaSMX7PD9aCtllt/fxJVe907+ZGFg7hLTdGbe0fv3H16dARtp7 1yUz7WEjAM+6XaPsNaV8sQbbPlPXtQL3Qtv0w8rA= From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values Date: Mon, 24 Oct 2022 18:37:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.0.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D16186 --- Comment #3 from Marek Polacek --- 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 anoth= er element has been assigned [-Wduplicate-enum] enum status { ok =3D 0, err =3D -1, foo, bar }; ^~~ j.c:1:15: note: element 'ok' also has value 0 enum status { ok =3D 0, err =3D -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 prese= nt, and warn if so.=