public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "frabar666 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/40193]  New: No built-in comparison operators for scoped enums (C++0x)
Date: Mon, 18 May 2009 21:58:00 -0000	[thread overview]
Message-ID: <bug-40193-17731@http.gcc.gnu.org/bugzilla/> (raw)

On trunk (also seen in gcc-4.4.0), gcc doesn't compile this snippet:
========================================
enum class E { A };
bool foo() { return E::A == E::A; }
========================================

in C++0x mode (cc1plus -quiet -std=c++0x enumtest.cpp -o /tmp/enumtest.s),
giving this error:
----------------------------------------
enumtest.cpp: In function 'bool foo()':
enumtest.cpp:2: error: invalid operands of types 'E' and 'E' to binary
'operator=='
----------------------------------------


I think this snippet is valid, since my interpretation of N2857's
[over.built]/15:
   For every T, where T is an enumeration type or pointer to effective
   object type, there exist candidate operator functions of the form
       bool operator<(T , T );
       bool operator>(T , T );
       bool operator<=(T , T );
       bool operator>=(T , T );
       bool operator==(T , T );
       bool operator!=(T , T );
is that type E should have a built-in operator==.


This is confirmed by the expected error message when compiling this snippet:
========================================
enum class E { A };
enum class F { B };
bool foo() { return E::A == F::B; }
========================================

which is:
----------------------------------------
enumtest2.cpp: In function 'bool foo()':
enumtest2.cpp:3: error: no match for 'operator==' in '(E)0 == (F)0'
enumtest2.cpp:3: note: candidates are: operator==(F, F) <built-in>
enumtest2.cpp:3: note:                 operator==(E, E) <built-in>
enumtest2.cpp:3: note:                 operator==(int, int) <built-in>
----------------------------------------

This message says there is indeed a built-in 'operator==(E, E)'. Shouldn't it
be found when compiling the first snippet?



This creates failures in Boost regression tests for runners using gcc-4.4.0 in
C++0x mode (as scoped enums have been enabled on that configuration recently).


-- 
           Summary: No built-in comparison operators for scoped enums
                    (C++0x)
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: frabar666 at gmail dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


             reply	other threads:[~2009-05-18 21:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 21:58 frabar666 at gmail dot com [this message]
2009-05-18 22:12 ` [Bug c++/40193] " paolo dot carlini at oracle dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-40193-17731@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).