* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
@ 2008-11-09 4:12 ` rbuergel at web dot de
2008-11-09 4:23 ` rbuergel at web dot de
` (17 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: rbuergel at web dot de @ 2008-11-09 4:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rbuergel at web dot de 2008-11-09 04:11 -------
extended testcase, this fails for other operators, too
enum class E { elem };
int main()
{
E::elem == E::elem;
E::elem != E::elem;
E::elem < E::elem;
E::elem <= E::elem;
E::elem > E::elem;
E::elem >= E::elem;
return 1;
}
Or am i missing something from the proposal? Maybe i have to define every
operator i want to use for every enum?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
2008-11-09 4:12 ` [Bug c++/38064] " rbuergel at web dot de
@ 2008-11-09 4:23 ` rbuergel at web dot de
2009-01-26 10:48 ` piotr dot wyderski at gmail dot com
` (16 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: rbuergel at web dot de @ 2008-11-09 4:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rbuergel at web dot de 2008-11-09 04:22 -------
ok, even for the case i misunderstood the proposal: there are still some
problems with it, making it unuseable.
enum class E { elem };
inline bool operator== (E c1, E c2)
{
return (int) c1 == (int) c2;
}
int main()
{
E::elem == E::elem; //works now
static_assert(E::elem == E::elem, ""); //fails
return 1;
}
tc2.cpp: In function 'int main()':
tc2.cpp:10: error: calls to overloaded operators cannot appear in a
constant-expression
... which leads to the conclusion, that strongly-typed enums can't be used in
constant-expression. That's definitely not intended by the proposal.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
2008-11-09 4:12 ` [Bug c++/38064] " rbuergel at web dot de
2008-11-09 4:23 ` rbuergel at web dot de
@ 2009-01-26 10:48 ` piotr dot wyderski at gmail dot com
2009-05-18 22:12 ` paolo dot carlini at oracle dot com
` (15 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: piotr dot wyderski at gmail dot com @ 2009-01-26 10:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from piotr dot wyderski at gmail dot com 2009-01-26 10:48 -------
The bug is definitely confirmed and it still happens on GCC-4.4.0 trunk
(revision 143673).
--
piotr dot wyderski at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |piotr dot wyderski at gmail
| |dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (2 preceding siblings ...)
2009-01-26 10:48 ` piotr dot wyderski at gmail dot com
@ 2009-05-18 22:12 ` paolo dot carlini at oracle dot com
2009-05-25 15:15 ` steven at gcc dot gnu dot org
` (14 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-05-18 22:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from paolo dot carlini at oracle dot com 2009-05-18 22:12 -------
*** Bug 40193 has been marked as a duplicate of this bug. ***
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |frabar666 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (3 preceding siblings ...)
2009-05-18 22:12 ` paolo dot carlini at oracle dot com
@ 2009-05-25 15:15 ` steven at gcc dot gnu dot org
2009-05-25 16:12 ` paolo dot carlini at oracle dot com
` (13 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: steven at gcc dot gnu dot org @ 2009-05-25 15:15 UTC (permalink / raw)
To: gcc-bugs
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-05-25 15:15:07
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (4 preceding siblings ...)
2009-05-25 15:15 ` steven at gcc dot gnu dot org
@ 2009-05-25 16:12 ` paolo dot carlini at oracle dot com
2009-05-25 16:45 ` jason at gcc dot gnu dot org
` (12 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-05-25 16:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from paolo dot carlini at oracle dot com 2009-05-25 16:11 -------
CC-ing Jason...
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (5 preceding siblings ...)
2009-05-25 16:12 ` paolo dot carlini at oracle dot com
@ 2009-05-25 16:45 ` jason at gcc dot gnu dot org
2009-05-25 18:32 ` ian at airs dot com
` (11 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-05-25 16:45 UTC (permalink / raw)
To: gcc-bugs
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jason at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2009-05-25 15:15:07 |2009-05-25 16:45:17
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (6 preceding siblings ...)
2009-05-25 16:45 ` jason at gcc dot gnu dot org
@ 2009-05-25 18:32 ` ian at airs dot com
2009-05-25 23:01 ` jason at gcc dot gnu dot org
` (10 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: ian at airs dot com @ 2009-05-25 18:32 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from ian at airs dot com 2009-05-25 18:32 -------
With unscoped enums the similar code works because cp_build_binary_op applies
the default integral promotions to the enums, and winds up comparing two int
values. The promotions are not applied to scoped enums because
default_conversion checks INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P. I would
guess that this would work if several checks in cp_build_binary_op also checked
for ENUMERAL_TYPE in cases where they currently check for INTEGER_TYPE. But I
haven't tried to read the standard to understand where the right fix is.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (7 preceding siblings ...)
2009-05-25 18:32 ` ian at airs dot com
@ 2009-05-25 23:01 ` jason at gcc dot gnu dot org
2009-05-25 23:07 ` jason at gcc dot gnu dot org
` (9 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-05-25 23:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from jason at gcc dot gnu dot org 2009-05-25 23:01 -------
Subject: Bug 38064
Author: jason
Date: Mon May 25 23:01:02 2009
New Revision: 147854
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147854
Log:
PR c++/38064
* typeck.c (cp_build_binary_op): Allow ENUMERAL_TYPE in
arithmetic comparisons.
(cp_common_type): Handle scoped enums.
* call.c (promoted_arithmetic_type_p): Don't use INTEGRAL_TYPE_P.
(add_builtin_candidate, add_builtin_candidates): Likewise.
(convert_like_real): Likewise.
* class.c (check_bitfield_decl): Likewise.
* decl.c (check_static_variable_definition): Likewise.
(compute_array_index_type): Likewise.
* decl2.c (grokbitfield): Likewise.
* init.c (build_new_1): Likewise.
* pt.c (convert_nontype_argument): Likewise.
(current_instantiation): Likewise.
* tree.c (pod_type_p): Likewise.
* typeck.c (build_static_cast_1): Likewise.
(build_reinterpret_cast_1): Likewise.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/enum3.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/cp/class.c
trunk/gcc/cp/decl.c
trunk/gcc/cp/decl2.c
trunk/gcc/cp/init.c
trunk/gcc/cp/pt.c
trunk/gcc/cp/tree.c
trunk/gcc/cp/typeck.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (8 preceding siblings ...)
2009-05-25 23:01 ` jason at gcc dot gnu dot org
@ 2009-05-25 23:07 ` jason at gcc dot gnu dot org
2009-05-25 23:12 ` jason at gcc dot gnu dot org
` (8 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-05-25 23:07 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from jason at gcc dot gnu dot org 2009-05-25 23:07 -------
Subject: Bug 38064
Author: jason
Date: Mon May 25 23:07:05 2009
New Revision: 147855
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147855
Log:
PR c++/38064
* typeck.c (cp_build_binary_op): Allow ENUMERAL_TYPE in
arithmetic comparisons.
(cp_common_type): Handle scoped enums.
Added:
branches/gcc-4_4-branch/gcc/testsuite/g++.dg/cpp0x/enum3.C
- copied unchanged from r147854, trunk/gcc/testsuite/g++.dg/cpp0x/enum3.C
Modified:
branches/gcc-4_4-branch/gcc/cp/ChangeLog
branches/gcc-4_4-branch/gcc/cp/typeck.c
branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (9 preceding siblings ...)
2009-05-25 23:07 ` jason at gcc dot gnu dot org
@ 2009-05-25 23:12 ` jason at gcc dot gnu dot org
2009-08-10 21:38 ` pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-05-25 23:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from jason at gcc dot gnu dot org 2009-05-25 23:12 -------
Fixed for 4.4.1.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (10 preceding siblings ...)
2009-05-25 23:12 ` jason at gcc dot gnu dot org
@ 2009-08-10 21:38 ` pinskia at gcc dot gnu dot org
2009-08-10 21:38 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-08-10 21:38 UTC (permalink / raw)
To: gcc-bugs
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.4.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (11 preceding siblings ...)
2009-08-10 21:38 ` pinskia at gcc dot gnu dot org
@ 2009-08-10 21:38 ` pinskia at gcc dot gnu dot org
2010-04-26 11:23 ` redi at gcc dot gnu dot org
` (5 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-08-10 21:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from pinskia at gcc dot gnu dot org 2009-08-10 21:37 -------
*** Bug 41030 has been marked as a duplicate of this bug. ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msclrhd at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (12 preceding siblings ...)
2009-08-10 21:38 ` pinskia at gcc dot gnu dot org
@ 2010-04-26 11:23 ` redi at gcc dot gnu dot org
2010-04-26 17:50 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-04-26 11:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from redi at gcc dot gnu dot org 2010-04-26 11:23 -------
This is fixed for equality operators but not relational operators
enum class E { Foo, Bar };
bool b2 = E::Foo < E::Bar;
--
redi at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|FIXED |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (13 preceding siblings ...)
2010-04-26 11:23 ` redi at gcc dot gnu dot org
@ 2010-04-26 17:50 ` pinskia at gcc dot gnu dot org
2010-04-26 23:07 ` redi at gcc dot gnu dot org
` (3 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-04-26 17:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #12 from pinskia at gcc dot gnu dot org 2010-04-26 17:50 -------
(In reply to comment #11)
> This is fixed for equality operators but not relational operators
>
> enum class E { Foo, Bar };
> bool b2 = E::Foo < E::Bar;
Is that even allowed for normal enums?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (14 preceding siblings ...)
2010-04-26 17:50 ` pinskia at gcc dot gnu dot org
@ 2010-04-26 23:07 ` redi at gcc dot gnu dot org
2010-05-04 19:01 ` jason at gcc dot gnu dot org
` (2 subsequent siblings)
18 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-04-26 23:07 UTC (permalink / raw)
To: gcc-bugs
------- Comment #13 from redi at gcc dot gnu dot org 2010-04-26 23:07 -------
(In reply to comment #12)
> Is that even allowed for normal enums?
yes, unscoped enums will be promoted to int
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (15 preceding siblings ...)
2010-04-26 23:07 ` redi at gcc dot gnu dot org
@ 2010-05-04 19:01 ` jason at gcc dot gnu dot org
2010-05-04 19:03 ` jason at gcc dot gnu dot org
2010-05-04 19:04 ` jason at gcc dot gnu dot org
18 siblings, 0 replies; 21+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-05-04 19:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #14 from jason at gcc dot gnu dot org 2010-05-04 19:01 -------
Subject: Bug 38064
Author: jason
Date: Tue May 4 19:01:13 2010
New Revision: 159042
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159042
Log:
PR c++/38064
* typeck.c (cp_build_binary_op): Allow enums for <> as well.
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/typeck.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/g++.dg/cpp0x/enum3.C
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (16 preceding siblings ...)
2010-05-04 19:01 ` jason at gcc dot gnu dot org
@ 2010-05-04 19:03 ` jason at gcc dot gnu dot org
2010-05-04 19:04 ` jason at gcc dot gnu dot org
18 siblings, 0 replies; 21+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-05-04 19:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #15 from jason at gcc dot gnu dot org 2010-05-04 19:03 -------
Subject: Bug 38064
Author: jason
Date: Tue May 4 19:03:00 2010
New Revision: 159043
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159043
Log:
PR c++/38064
* typeck.c (cp_build_binary_op): Allow enums for <> as well.
Modified:
branches/gcc-4_5-branch/gcc/cp/ChangeLog
branches/gcc-4_5-branch/gcc/cp/typeck.c
branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
branches/gcc-4_5-branch/gcc/testsuite/g++.dg/cpp0x/enum3.C
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread
* [Bug c++/38064] [c++0x] operator== doesn't work for enum classes
2008-11-09 4:04 [Bug c++/38064] New: [c++0x] operator== doesn't work for enum classes rbuergel at web dot de
` (17 preceding siblings ...)
2010-05-04 19:03 ` jason at gcc dot gnu dot org
@ 2010-05-04 19:04 ` jason at gcc dot gnu dot org
18 siblings, 0 replies; 21+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-05-04 19:04 UTC (permalink / raw)
To: gcc-bugs
------- Comment #16 from jason at gcc dot gnu dot org 2010-05-04 19:04 -------
Other comparisons fixed for 4.5.1.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |FIXED
Target Milestone|4.4.1 |4.5.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
^ permalink raw reply [flat|nested] 21+ messages in thread