re PR c++/56749 (weird interaction between scoped enum used as non-type template...
authorJason Merrill <jason@redhat.com>
Wed, 27 Mar 2013 18:21:12 +0000 (14:21 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 27 Mar 2013 18:21:12 +0000 (14:21 -0400)
PR c++/56749
* semantics.c (finish_qualified_id_expr): Return early
for enum scope.

From-SVN: r197166

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/enum24.C [new file with mode: 0644]

index 5a1cac41124434024dbb2ffc33309f2f4b3af7e1..714522e5fd7f0a454d66bdf95a188a2ba73bb5ec 100644 (file)
@@ -1,3 +1,9 @@
+2013-03-27  Jason Merrill  <jason@redhat.com>
+
+       PR c++/56749
+       * semantics.c (finish_qualified_id_expr): Return early
+       for enum scope.
+
 2013-03-26  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
        * call.c (build_new_method_call_1): Use INDIRECT_REF_P.
index fd77725c254e262f2f1a48d12f772b9fa9d23ba4..72b884ef2e496ce89ccc055c17ddc62648f4cbfe 100644 (file)
@@ -1762,6 +1762,10 @@ finish_qualified_id_expr (tree qualifying_class,
       return expr;
     }
 
+  /* No need to check access within an enum.  */
+  if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE)
+    return expr;
+
   /* Within the scope of a class, turn references to non-static
      members into expression of the form "this->...".  */
   if (template_arg_p)
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum24.C b/gcc/testsuite/g++.dg/cpp0x/enum24.C
new file mode 100644 (file)
index 0000000..6099656
--- /dev/null
@@ -0,0 +1,57 @@
+// PR c++/56749
+// { dg-require-effective-target c++11 }
+
+enum normal_enum
+{
+    not_scoped1,
+    not_scoped2
+};
+
+enum class scoped_enum
+{
+    scoped1,
+    scoped2
+};
+
+template <normal_enum N=not_scoped1>
+class A
+{
+public:
+    template <typename T>
+        void fun ()
+        {
+        }
+};
+
+template <scoped_enum N=scoped_enum::scoped1>
+class B
+{
+public:
+    template <typename T>
+        void fun ()
+        {
+        }
+};
+
+
+template <typename T>
+void tfun ()
+{
+    A<> a;
+    a.fun<char>(); //<------------ THIS IS FINE
+
+    B<> b_defaulted;
+    B<scoped_enum::scoped1> b_explicited;
+
+    b_defaulted.fun<char>();          //<------------ UNEXPECTED: THIS FAILS 
+    b_defaulted.template fun<char>(); //<------------ THIS IS FINE
+
+    b_explicited.fun<char>();         //<------------ UNEXPECTED: THIS FAILS 
+    b_explicited.template fun<char>();//<------------ THIS IS FINE
+}
+
+int main(int argc, char const *argv[])
+{
+    tfun<int>();
+    return 0;
+}