On 01/23/2014 04:50 PM, Jason Merrill wrote:
On 01/23/2014 10:30 AM, Paolo Carlini wrote:
To be clear if we use %qT with nested_name_specifier we get:

58980.C:5:8: error: ‘typename A< <template-parameter-1-1> >::B’ has not
been declared

which frankly seems suboptimal to me, both vs the non-template case and
the use of typename.
If you want to break apart the typename and do %T::%E with TYPE_CONTEXT (nested_name_specifier) on the left side, that's fine too.
Ah, Ok, I was missing that we really want to use TYPE_CONTEXT. To confirm, then we get:

58980.C:5:8: error: ‘A< <template-parameter-1-1> >::B’ has not been declared

I'm finishing testing the below.

Thanks,
Paolo.

///////////////////////
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 206958)
+++ cp/parser.c (working copy)
@@ -15469,9 +15469,18 @@ cp_parser_enum_specifier (cp_parser* parser)
            error_at (type_start_token->location, "cannot add an enumerator "
                      "list to a template instantiation");
 
+         if (TREE_CODE (nested_name_specifier) == TYPENAME_TYPE)
+           {
+             error_at (type_start_token->location,
+                       "%<%T::%E%> has not been declared",
+                       TYPE_CONTEXT (nested_name_specifier),
+                       nested_name_specifier);
+             type = error_mark_node;
+           }
          /* 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))
+         else if (prev_scope && !is_ancestor (prev_scope,
+                                              nested_name_specifier))
            {
              if (at_namespace_scope_p ())
                error_at (type_start_token->location,
@@ -15480,7 +15489,8 @@ cp_parser_enum_specifier (cp_parser* parser)
                          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 %qD",
                          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 "has not been declared" }
+};

Reply via email to