Hi,

On 01/21/2014 03:55 PM, Jason Merrill wrote:
I think I would prefer to change the "child" assert to be MAYBE_CLASS_TYPE_P rather than CLASS_TYPE_P.
.. Ok, but then it seems to me that we have to explicitly handle the TYPENAME_TYPE case, otherwise we end up simply accepting the testcase (even if the template is instantiated!). Something like the below...

Paolo.

//////////////////////////
Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c    (revision 206880)
+++ cp/name-lookup.c    (working copy)
@@ -2723,12 +2723,15 @@ is_ancestor (tree root, tree child)
               || TREE_CODE (root) == FUNCTION_DECL
               || CLASS_TYPE_P (root)));
   gcc_assert ((TREE_CODE (child) == NAMESPACE_DECL
-              || CLASS_TYPE_P (child)));
+              || MAYBE_CLASS_TYPE_P (child)));
 
   /* The global namespace encloses everything.  */
   if (root == global_namespace)
     return true;
 
+  if (TREE_CODE (child) == TYPENAME_TYPE)
+    return false;
+
   while (true)
     {
       /* If we've run out of scopes, stop.  */
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 206880)
+++ cp/parser.c (working copy)
@@ -15476,11 +15476,12 @@ cp_parser_enum_specifier (cp_parser* parser)
              if (at_namespace_scope_p ())
                error_at (type_start_token->location,
                          "declaration of %qD in namespace %qD which does not "
-                         "enclose %qD",
+                         "enclose %qT",
                          type, prev_scope, nested_name_specifier);
              else
                error_at (type_start_token->location,
-                         "declaration of %qD in %qD which does not enclose 
%qD",
+                         "declaration of %qD in %qD which does not "
+                         "enclose %qT",
                          type, prev_scope, nested_name_specifier);
              type = error_mark_node;
            }
Index: testsuite/g++.dg/parse/enum11.C
===================================================================
--- testsuite/g++.dg/parse/enum11.C     (revision 0)
+++ testsuite/g++.dg/parse/enum11.C     (working copy)
@@ -0,0 +1,6 @@
+// PR c++/58980
+
+template<typename> struct A
+{ 
+  enum A::B::C {};  // { dg-error "does not enclose" }
+};

Reply via email to