===================================================================
@@ -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. */
===================================================================
@@ -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;
}
===================================================================
@@ -0,0 +1,6 @@
+// PR c++/58980
+
+template<typename> struct A
+{
+ enum A::B::C {}; // { dg-error "does not enclose" }
+};