public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100879] New: gcc is complaining of a signed compare when comparing enums of different types (same underlying type)
@ 2021-06-02 17:15 andre at kostur dot net
  2021-06-07  9:02 ` [Bug c++/100879] [10/11/12 Regression] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: andre at kostur dot net @ 2021-06-02 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100879
           Summary: gcc is complaining of a signed compare when comparing
                    enums of different types (same underlying type)
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andre at kostur dot net
  Target Milestone: ---

With the following test code:

enum e1 { e1val };

enum e2 { e3val };

int main( int, char * [] ) {
   if ( e1val == e3val ) return 1;
}

The compiler emits two warnings:
<source>: In function 'int main(int, char**)':
<source>:6:15: warning: comparison between 'enum e1' and 'enum e2'
[-Wenum-compare]
    6 |    if ( e1val == e3val ) return 1;
      |         ~~~~~~^~~~~~~~
<source>:6:15: warning: comparison between types 'e1' and 'e2' [-Wsign-compare]

The first is correct, but the second warning seems wrong.  There is no sign
mismatch as both enums would have the same underlying type.

gcc 9.3 does not seem to suffer this problem.  gcc 10.1 does, and appears every
version up to at least 11.1 does.  (Checked on compiler-explorer)

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

* [Bug c++/100879] [10/11/12 Regression] gcc is complaining of a signed compare when comparing enums of different types (same underlying type)
  2021-06-02 17:15 [Bug c++/100879] New: gcc is complaining of a signed compare when comparing enums of different types (same underlying type) andre at kostur dot net
@ 2021-06-07  9:02 ` rguenth at gcc dot gnu.org
  2021-06-08 21:49 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-07  9:02 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|gcc is complaining of a     |[10/11/12 Regression] gcc
                   |signed compare when         |is complaining of a signed
                   |comparing enums of          |compare when comparing
                   |different types (same       |enums of different types
                   |underlying type)            |(same underlying type)
           Keywords|                            |diagnostic
   Target Milestone|---                         |10.4

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

* [Bug c++/100879] [10/11/12 Regression] gcc is complaining of a signed compare when comparing enums of different types (same underlying type)
  2021-06-02 17:15 [Bug c++/100879] New: gcc is complaining of a signed compare when comparing enums of different types (same underlying type) andre at kostur dot net
  2021-06-07  9:02 ` [Bug c++/100879] [10/11/12 Regression] " rguenth at gcc dot gnu.org
@ 2021-06-08 21:49 ` jason at gcc dot gnu.org
  2021-06-09  0:42 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2021-06-08 21:49 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-06-08
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
                 CC|                            |jason at gcc dot gnu.org
     Ever confirmed|0                           |1

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

* [Bug c++/100879] [10/11/12 Regression] gcc is complaining of a signed compare when comparing enums of different types (same underlying type)
  2021-06-02 17:15 [Bug c++/100879] New: gcc is complaining of a signed compare when comparing enums of different types (same underlying type) andre at kostur dot net
  2021-06-07  9:02 ` [Bug c++/100879] [10/11/12 Regression] " rguenth at gcc dot gnu.org
  2021-06-08 21:49 ` jason at gcc dot gnu.org
@ 2021-06-09  0:42 ` cvs-commit at gcc dot gnu.org
  2021-06-09  0:46 ` jason at gcc dot gnu.org
  2021-06-21 20:42 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-09  0:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:087253b9951766cbd93286b804ebb1ab59197aa8

commit r12-1314-g087253b9951766cbd93286b804ebb1ab59197aa8
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 8 17:48:49 2021 -0400

    c++: remove redundant warning [PR100879]

    Before my r277864, build_new_op promoted enums to int before passing them
on
    to cp_build_binary_op; after that commit, it doesn't, so
    warn_for_sign_compare sees the enum operands and gives a redundant warning.
    This warning dates back to 1995, and seems to have been dead code for a
long
    time--likely since build_new_op was added in 1997--so let's just remove it.

            PR c++/100879

    gcc/c-family/ChangeLog:

            * c-warn.c (warn_for_sign_compare): Remove C++ enum mismatch
            warning.

    gcc/testsuite/ChangeLog:

            * g++.dg/diagnostic/enum3.C: New test.

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

* [Bug c++/100879] [10/11/12 Regression] gcc is complaining of a signed compare when comparing enums of different types (same underlying type)
  2021-06-02 17:15 [Bug c++/100879] New: gcc is complaining of a signed compare when comparing enums of different types (same underlying type) andre at kostur dot net
                   ` (2 preceding siblings ...)
  2021-06-09  0:42 ` cvs-commit at gcc dot gnu.org
@ 2021-06-09  0:46 ` jason at gcc dot gnu.org
  2021-06-21 20:42 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2021-06-09  0:46 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |12.0
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 12, thanks.

That the warning used -Wsign-compare seems to be because it was associated with
that option before -Wenum-compare was added, and never updated perhaps because
it was dead code for a long time.

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

* [Bug c++/100879] [10/11/12 Regression] gcc is complaining of a signed compare when comparing enums of different types (same underlying type)
  2021-06-02 17:15 [Bug c++/100879] New: gcc is complaining of a signed compare when comparing enums of different types (same underlying type) andre at kostur dot net
                   ` (3 preceding siblings ...)
  2021-06-09  0:46 ` jason at gcc dot gnu.org
@ 2021-06-21 20:42 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-21 20:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:4f2819223873266b4cdfa7af54752a37d1ebd665

commit r11-8628-g4f2819223873266b4cdfa7af54752a37d1ebd665
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 8 17:48:49 2021 -0400

    c++: remove redundant warning [PR100879]

    Before my r277864, build_new_op promoted enums to int before passing them
on
    to cp_build_binary_op; after that commit, it doesn't, so
    warn_for_sign_compare sees the enum operands and gives a redundant warning.
    This warning dates back to 1995, and seems to have been dead code for a
long
    time--likely since build_new_op was added in 1997--so let's just remove it.

            PR c++/100879

    gcc/c-family/ChangeLog:

            * c-warn.c (warn_for_sign_compare): Remove C++ enum mismatch
            warning.

    gcc/testsuite/ChangeLog:

            * g++.dg/diagnostic/enum3.C: New test.

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

end of thread, other threads:[~2021-06-21 20:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 17:15 [Bug c++/100879] New: gcc is complaining of a signed compare when comparing enums of different types (same underlying type) andre at kostur dot net
2021-06-07  9:02 ` [Bug c++/100879] [10/11/12 Regression] " rguenth at gcc dot gnu.org
2021-06-08 21:49 ` jason at gcc dot gnu.org
2021-06-09  0:42 ` cvs-commit at gcc dot gnu.org
2021-06-09  0:46 ` jason at gcc dot gnu.org
2021-06-21 20:42 ` cvs-commit at gcc dot gnu.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).