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

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).