===================================================================
@@ -15471,16 +15471,19 @@ cp_parser_enum_specifier (cp_parser* parser)
/* If that scope does not contain the scope in which the
class was originally declared, the program is invalid. */
- if (prev_scope && !is_ancestor (prev_scope, nested_name_specifier))
+ if (prev_scope
+ && (TREE_CODE (nested_name_specifier) == TYPENAME_TYPE
+ || !is_ancestor (prev_scope, nested_name_specifier)))
{
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" }
+};