This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/85587, wrong error with scoped enum and template


Now that we're doing normal handling of qualified names in a template,
we need to handle the case of an unresolved enumerator name.

Jakub, should this also go into 8.1?

Tested x86_64-pc-linux-gnu, applying to trunk.
commit f7dae5dc1933f836e47cafeab2ff2bd5d80e4eeb
Author: Jason Merrill <jason@redhat.com>
Date:   Tue May 1 13:41:21 2018 -0400

            PR c++/85587 - error with scoped enum in template.
    
            * semantics.c (finish_qualified_id_expr): Don't return an
            unqualified IDENTIFIER_NODE.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 8c893ed64b0..4568bb96f3b 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2061,7 +2061,8 @@ finish_qualified_id_expr (tree qualifying_class,
     }
 
   /* No need to check access within an enum.  */
-  if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE)
+  if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
+      && TREE_CODE (expr) != IDENTIFIER_NODE)
     return expr;
 
   /* Within the scope of a class, turn references to non-static
diff --git a/gcc/testsuite/g++.dg/cpp0x/scoped_enum8.C b/gcc/testsuite/g++.dg/cpp0x/scoped_enum8.C
new file mode 100644
index 00000000000..3bd66395787
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/scoped_enum8.C
@@ -0,0 +1,25 @@
+// PR c++/85587
+// { dg-do compile { target c++11 } }
+
+template <int N>
+struct S
+{
+  enum class T
+  {
+    E, F
+  };
+  void foo ();
+};
+
+template <int N>
+void S<N>::foo ()
+{
+  decltype (T::F) t;
+}
+
+void
+bar ()
+{
+  S<0> s;
+  s.foo ();
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]