public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values
       [not found] <bug-16186-4@http.gcc.gnu.org/bugzilla/>
@ 2022-10-24 15:25 ` pinskia at gcc dot gnu.org
  2022-10-24 18:37 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-24 15:25 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 107377 has been marked as a duplicate of this bug. ***

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

* [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values
       [not found] <bug-16186-4@http.gcc.gnu.org/bugzilla/>
  2022-10-24 15:25 ` [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values pinskia at gcc dot gnu.org
@ 2022-10-24 18:37 ` mpolacek at gcc dot gnu.org
  2022-10-24 18:43 ` marxin at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-24 18:37 UTC (permalink / raw)
  To: gcc-bugs

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.

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

* [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values
       [not found] <bug-16186-4@http.gcc.gnu.org/bugzilla/>
  2022-10-24 15:25 ` [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values pinskia at gcc dot gnu.org
  2022-10-24 18:37 ` mpolacek at gcc dot gnu.org
@ 2022-10-24 18:43 ` marxin at gcc dot gnu.org
  2022-10-24 18:48 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-10-24 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #3)
> FWIW, Clang implements this warning:

Oh, I was unable to find the option (only tried -Werror and -Wextra).

@Marek: please add it!

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

* [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values
       [not found] <bug-16186-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2022-10-24 18:43 ` marxin at gcc dot gnu.org
@ 2022-10-24 18:48 ` mpolacek at gcc dot gnu.org
  2022-10-24 19:18 ` marxin at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-24 18:48 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #4)
> @Marek: please add it!

Anything to oblige ye, my fellow.

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

* [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values
       [not found] <bug-16186-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2022-10-24 18:48 ` mpolacek at gcc dot gnu.org
@ 2022-10-24 19:18 ` marxin at gcc dot gnu.org
  2023-03-10 20:12 ` trashyankes at wp dot pl
  2023-03-13 13:44 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-10-24 19:18 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=107386

--- Comment #6 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #5)
> (In reply to Martin Liška from comment #4)
> > @Marek: please add it!
> 
> Anything to oblige ye, my fellow.

It would pay off my friend (PR107386).

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

* [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values
       [not found] <bug-16186-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2022-10-24 19:18 ` marxin at gcc dot gnu.org
@ 2023-03-10 20:12 ` trashyankes at wp dot pl
  2023-03-13 13:44 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: trashyankes at wp dot pl @ 2023-03-10 20:12 UTC (permalink / raw)
  To: gcc-bugs

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

trashyankes at wp dot pl changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |trashyankes at wp dot pl

--- Comment #7 from trashyankes at wp dot pl ---
Should be way to disable/enable this warning per `enum`?
Like:

```
enum [[gnu::enum_unique]] X
{
  I = 1,
  J = 2,
};

enum [[gnu::enum_not_unique]] Y
{
  K = 1,
  L = 1,
};

```

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

* [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values
       [not found] <bug-16186-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2023-03-10 20:12 ` trashyankes at wp dot pl
@ 2023-03-13 13:44 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-13 13:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to trashyankes from comment #7)
> Should be way to disable/enable this warning per `enum`?
> Like:
> 
> ```
> enum [[gnu::enum_unique]] X
> {
>   I = 1,
>   J = 2,
> };
> 
> enum [[gnu::enum_not_unique]] Y
> {
>   K = 1,
>   L = 1,
> };
> 
> ```

No, it should warn solely if enumerator gets implicitly assigned value of some
other enumerator.  After all, the clang wording also mentions that:
element 'D' has been implicitly assigned 5 which another element has been
assigned [-Wduplicate-enum]
If there is = value for it, we should never warn, that is most likely
completely intentional.
Of course, we should use better wording, because we should talk about
enumerators, not elements...

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

* [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values
  2004-06-24 23:09 [Bug c/16186] New: " austern at apple dot com
@ 2004-06-29  2:56 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-29  2:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-29 02:47 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2004-06-29 02:47:43
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16186


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

end of thread, other threads:[~2023-03-13 13:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-16186-4@http.gcc.gnu.org/bugzilla/>
2022-10-24 15:25 ` [Bug c/16186] gcc should have an option to warn about enumerations with duplicate values pinskia at gcc dot gnu.org
2022-10-24 18:37 ` mpolacek at gcc dot gnu.org
2022-10-24 18:43 ` marxin at gcc dot gnu.org
2022-10-24 18:48 ` mpolacek at gcc dot gnu.org
2022-10-24 19:18 ` marxin at gcc dot gnu.org
2023-03-10 20:12 ` trashyankes at wp dot pl
2023-03-13 13:44 ` jakub at gcc dot gnu.org
2004-06-24 23:09 [Bug c/16186] New: " austern at apple dot com
2004-06-29  2:56 ` [Bug c/16186] " pinskia at gcc dot gnu dot 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).