On 2/26/19 5:13 PM, Marek Polacek wrote:
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);
Hmm, surely we want to handle class scope enums here, too? Maybe
!TYPE_FUNCTION_SCOPE_P instead.
Jason