re PR c++/66781 ("confused by earlier errors, bailing out" with wrong enum within...
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 21 Oct 2015 22:52:45 +0000 (22:52 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 21 Oct 2015 22:52:45 +0000 (22:52 +0000)
/cp
2015-10-21  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/66781
* parser.c (cp_parser_enum_specifier): Upon error_at set
nested_name_specifier to error_mark_node; improve error message.

/testsuite
2015-10-21  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/66781
* g++.dg/parse/enum13.C: New.

/cp
2015-10-21  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/67847
* parser.c (cp_parser_enum_specifier): Reject a nested_name_specifier
which doesn't name a class or namespace.

/testsuite
2015-10-21  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/67847
* g++.dg/parse/enum12.C: New.

From-SVN: r229156

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/enum12.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/enum13.C [new file with mode: 0644]

index 2a9e873320d8ee694f1d2934810cb8fc6ed7555a..0ed4e29615da0d4e0c9cc18a17821cfcc5cbd611 100644 (file)
@@ -1,3 +1,15 @@
+2015-10-21  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/66781
+       * parser.c (cp_parser_enum_specifier): Upon error_at set
+       nested_name_specifier to error_mark_node; improve error message.
+
+2015-10-21  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/67847
+       * parser.c (cp_parser_enum_specifier): Reject a nested_name_specifier
+       which doesn't name a class or namespace.
+
 2015-10-21  Ilya Enkovich  <enkovich.gnu@gmail.com>
 
        * call.c (build_conditional_expr_1): Use boolean vector
index cfe5468a8b5039c458cab9cc49e2c23dac1afb7c..7555bf3c87aefedf7f05c456e4ee444713285538 100644 (file)
@@ -16655,8 +16655,12 @@ cp_parser_enum_specifier (cp_parser* parser)
       else if (nested_name_specifier == error_mark_node)
        /* We already issued an error.  */;
       else
-       error_at (type_start_token->location,
-                 "%qD is not an enumerator-name", identifier);
+       {
+         error_at (type_start_token->location,
+                   "%qD does not name an enumeration in %qT",
+                   identifier, nested_name_specifier);
+         nested_name_specifier = error_mark_node;
+       }
     }
   else
     {
@@ -16783,6 +16787,14 @@ cp_parser_enum_specifier (cp_parser* parser)
                        nested_name_specifier);
              type = error_mark_node;
            }
+         else if (TREE_CODE (nested_name_specifier) != NAMESPACE_DECL
+                  && !CLASS_TYPE_P (nested_name_specifier))
+           {
+             error_at (type_start_token->location, "nested name specifier "
+                       "%qT for enum declaration does not name a class "
+                       "or namespace", 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.  */
          else if (prev_scope && !is_ancestor (prev_scope,
index 1c31c22bfeb7856e3578afbc9cc1466e83e0fe56..ef63b1b076534b5c744ca9b9dc2724a85e786a2f 100644 (file)
@@ -1,3 +1,13 @@
+2015-10-21  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/66781
+       * g++.dg/parse/enum13.C: New.
+
+2015-10-21  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/67847
+       * g++.dg/parse/enum12.C: New.
+
 2015-10-21  Martin Sebor  <msebor@redhat.com>
 
        PR driver/68043
diff --git a/gcc/testsuite/g++.dg/parse/enum12.C b/gcc/testsuite/g++.dg/parse/enum12.C
new file mode 100644 (file)
index 0000000..835dacd
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/67847
+
+template < typename T > 
+class D
+{
+  enum T::Color {R, G, B} c; // { dg-error "nested name specifier" }
+};
diff --git a/gcc/testsuite/g++.dg/parse/enum13.C b/gcc/testsuite/g++.dg/parse/enum13.C
new file mode 100644 (file)
index 0000000..102f219
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/66781
+
+class foo
+{
+public:
+  enum foo::bar{};  // { dg-error "does not name an enumeration" }
+  foo::bar baz;
+};