Here we ICE because the unscoped enum's context is a FUNCTION_DECL, which push_using_decl can't handle.
http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#1742 says this is well-formed (but the scoped enum case is ill-formed). Nevertheless, the DR hasn't been resolved either way yet, and trying to accept a FUNCTION_DECL as a USING_DECL_SCOPE seems like a lot of work, and ultimately maybe both cases will be deemed ill-formed. This patch fixes the ICE by giving the pre-r211479 error while simultaneously keeping using-enum-[12].C working. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-02-26 Marek Polacek <pola...@redhat.com> PR c++/89511 - ICE with using-declarations and unscoped enumerator. * parser.c (cp_parser_using_declaration): For an unscoped enum only use its context if it's a namespace declaration. * g++.dg/cpp0x/using-enum-3.C: New test. diff --git gcc/cp/parser.c gcc/cp/parser.c index e976008e94d..361dc9d065e 100644 --- gcc/cp/parser.c +++ gcc/cp/parser.c @@ -19412,7 +19412,8 @@ cp_parser_using_declaration (cp_parser* parser, /*is_declaration=*/true); if (!qscope) qscope = global_namespace; - else if (UNSCOPED_ENUM_P (qscope)) + else if (UNSCOPED_ENUM_P (qscope) + && TREE_CODE (CP_TYPE_CONTEXT (qscope)) == NAMESPACE_DECL) qscope = CP_TYPE_CONTEXT (qscope); if (access_declaration_p && cp_parser_error_occurred (parser)) diff --git gcc/testsuite/g++.dg/cpp0x/using-enum-3.C gcc/testsuite/g++.dg/cpp0x/using-enum-3.C new file mode 100644 index 00000000000..1fb4f95304c --- /dev/null +++ gcc/testsuite/g++.dg/cpp0x/using-enum-3.C @@ -0,0 +1,8 @@ +// PR c++/89511 +// { dg-do compile { target c++11 } } + +void f () +{ + enum e { a }; + using e::a; // { dg-error "not a namespace or unscoped enum" } +}