re PR c++/38064 ([c++0x] operator== doesn't work for enum classes)

PR c++/38064
        * typeck.c (cp_build_binary_op): Allow ENUMERAL_TYPE in
        arithmetic comparisons.
        (cp_common_type): Handle scoped enums.

From-SVN: r147855
This commit is contained in:
Jason Merrill 2009-05-25 19:07:05 -04:00 committed by Jason Merrill
parent 7fa170ec2b
commit 355058f505
4 changed files with 47 additions and 9 deletions

View File

@ -1,3 +1,10 @@
2009-05-22 Jason Merrill <jason@redhat.com>
PR c++/38064
* typeck.c (cp_build_binary_op): Allow ENUMERAL_TYPE in
arithmetic comparisons.
(cp_common_type): Handle scoped enums.
2009-05-16 Jason Merrill <jason@redhat.com>
PR c++/40139

View File

@ -260,6 +260,19 @@ cp_common_type (tree t1, tree t2)
enum tree_code code2 = TREE_CODE (t2);
tree attributes;
/* In what follows, we slightly generalize the rules given in [expr] so
as to deal with `long long' and `complex'. First, merge the
attributes. */
attributes = (*targetm.merge_type_attributes) (t1, t2);
if (SCOPED_ENUM_P (t1) || SCOPED_ENUM_P (t2))
{
if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
return build_type_attribute_variant (t1, attributes);
else
return NULL_TREE;
}
/* FIXME: Attributes. */
gcc_assert (ARITHMETIC_TYPE_P (t1)
|| TREE_CODE (t1) == VECTOR_TYPE
@ -268,11 +281,6 @@ cp_common_type (tree t1, tree t2)
|| TREE_CODE (t2) == VECTOR_TYPE
|| UNSCOPED_ENUM_P (t2));
/* In what follows, we slightly generalize the rules given in [expr] so
as to deal with `long long' and `complex'. First, merge the
attributes. */
attributes = (*targetm.merge_type_attributes) (t1, t2);
/* If one type is complex, form the common type of the non-complex
components, then make that complex. Use T1 or T2 if it is the
required type. */
@ -3589,9 +3597,9 @@ cp_build_binary_op (location_t location,
build_type = boolean_type_node;
if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
|| code0 == COMPLEX_TYPE)
|| code0 == COMPLEX_TYPE || code0 == ENUMERAL_TYPE)
&& (code1 == INTEGER_TYPE || code1 == REAL_TYPE
|| code1 == COMPLEX_TYPE))
|| code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE))
short_compare = 1;
else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE)
|| (TYPE_PTRMEM_P (type0) && TYPE_PTRMEM_P (type1)))
@ -3863,9 +3871,10 @@ cp_build_binary_op (location_t location,
break;
}
if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
|| code0 == ENUMERAL_TYPE)
&& (code1 == INTEGER_TYPE || code1 == REAL_TYPE
|| code1 == COMPLEX_TYPE)))
|| code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE)))
arithmetic_types_p = 1;
else
{

View File

@ -1,3 +1,8 @@
2009-05-25 Jason Merrill <jason@redhat.com>
PR c++/38064
* g++.dg/cpp0x/enum3.C: New test.
2009-05-22 Zdenek Dvorak <ook@ucw.cz>
PR tree-optimization/40087

View File

@ -0,0 +1,17 @@
// PR c++/38064
// { dg-options "-std=c++0x" }
// { dg-do run }
enum class E { elem };
template <class T>
void f (T t);
bool f (bool b) { return b; }
int main()
{
E e = E::elem;
if (!f (e == E::elem))
return 1;
}