PR c++/89511 - ICE with using-declaration and unscoped enumerator.
authorMarek Polacek <polacek@redhat.com>
Wed, 27 Feb 2019 19:07:18 +0000 (19:07 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 27 Feb 2019 19:07:18 +0000 (19:07 +0000)
* 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
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/using-enum-3.C [new file with mode: 0644]

index 1ce758b..a2d16e1 100644 (file)
@@ -1,3 +1,9 @@
+2019-02-27  Marek Polacek  <polacek@redhat.com>
+
+       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  <paolo.carlini@oracle.com>
 
        PR c++/89488
index d9824e4..5f69403 100644 (file)
@@ -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))
index 9d6742c..eff4a81 100644 (file)
@@ -1,3 +1,8 @@
+2019-02-27  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/89511 - ICE with using-declaration and unscoped enumerator.
+       * g++.dg/cpp0x/using-enum-3.C: New test.
+
 2019-02-27  Jakub Jelinek  <jakub@redhat.com>
 
        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 (file)
index 0000000..edc1689
--- /dev/null
@@ -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" }
+};