From 867a4ad28e118776bedc3bb2571d91c898aa3398 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 27 Feb 2019 19:07:18 +0000 Subject: [PATCH] PR c++/89511 - ICE with using-declaration and unscoped enumerator. * parser.c (cp_parser_using_declaration): For an unscoped enum only use its context if it's not a function declaration. * g++.dg/cpp0x/using-enum-3.C: New test. From-SVN: r269262 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/using-enum-3.C | 21 +++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/using-enum-3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1ce758b15f6..a2d16e15b4a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-02-27 Marek Polacek + + PR c++/89511 - ICE with using-declaration and unscoped enumerator. + * parser.c (cp_parser_using_declaration): For an unscoped enum + only use its context if it's not a function declaration. + 2019-02-27 Paolo Carlini PR c++/89488 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d9824e40803..5f694033496 100644 --- a/gcc/cp/parser.c +++ b/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) + && !TYPE_FUNCTION_SCOPE_P (qscope)) qscope = CP_TYPE_CONTEXT (qscope); if (access_declaration_p && cp_parser_error_occurred (parser)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9d6742c70b1..eff4a81d28b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-02-27 Marek Polacek + + PR c++/89511 - ICE with using-declaration and unscoped enumerator. + * g++.dg/cpp0x/using-enum-3.C: New test. + 2019-02-27 Jakub Jelinek PR tree-optimization/89280 diff --git a/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C b/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C new file mode 100644 index 00000000000..edc16890cb1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C @@ -0,0 +1,21 @@ +// 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" } +} + +struct S { + enum E { A }; + using E::A; // { dg-error "type .S. is not a base type for type .S." } +}; + +namespace N { + enum E { B }; +} + +struct T { + using N::E::B; // { dg-error "using-declaration for non-member at class scope" } +}; -- 2.11.4.GIT