From: Jason Merrill Date: Mon, 1 Apr 2013 21:18:11 +0000 (-0400) Subject: re PR c++/56793 (ICE with scoped enum) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c53d966d3176a8ebe1f88ad1b87a8a9e2bfbb96c;p=gcc.git re PR c++/56793 (ICE with scoped enum) PR c++/56793 * typeck.c (finish_class_member_access_expr): Handle enum scope. From-SVN: r197325 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c7e140ed579..7e58f704747 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2013-04-01 Jason Merrill + PR c++/56793 + * typeck.c (finish_class_member_access_expr): Handle enum scope. + PR c++/56794 * parser.c (cp_parser_range_for): Don't try to do auto deduction in a template if the type of the range is incomplete. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 763fc0b3b08..043d52ffaa7 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2684,6 +2684,23 @@ finish_class_member_access_expr (tree object, tree name, bool template_p, return error_mark_node; } + if (TREE_CODE (scope) == ENUMERAL_TYPE) + { + /* Looking up a member enumerator (c++/56793). */ + if (!TYPE_CLASS_SCOPE_P (scope) + || !DERIVED_FROM_P (TYPE_CONTEXT (scope), object_type)) + { + if (complain & tf_error) + error ("%<%D::%D%> is not a member of %qT", + scope, name, object_type); + return error_mark_node; + } + tree val = lookup_enumerator (scope, name); + if (TREE_SIDE_EFFECTS (object)) + val = build2 (COMPOUND_EXPR, TREE_TYPE (val), object, val); + return val; + } + gcc_assert (CLASS_TYPE_P (scope)); gcc_assert (identifier_p (name) || TREE_CODE (name) == BIT_NOT_EXPR); diff --git a/gcc/testsuite/g++.dg/cpp0x/enum25.C b/gcc/testsuite/g++.dg/cpp0x/enum25.C new file mode 100644 index 00000000000..cb2cf8f5363 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/enum25.C @@ -0,0 +1,18 @@ +// PR c++/56793 +// { dg-require-effective-target c++11 } + +struct A +{ + enum struct B {X, Y} b; +} a; + +enum struct D {X,Y}; +struct C { } c; + +int main () +{ + if (a.b == a.B::Y) + a.b = A::B::X; + + c.D::Y; // { dg-error "not a member" } +}